RuoVea.SM
10.0.0.1
dotnet add package RuoVea.SM --version 10.0.0.1
NuGet\Install-Package RuoVea.SM -Version 10.0.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RuoVea.SM" Version="10.0.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RuoVea.SM" Version="10.0.0.1" />
<PackageReference Include="RuoVea.SM" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add RuoVea.SM --version 10.0.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: RuoVea.SM, 10.0.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package RuoVea.SM@10.0.0.1
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=RuoVea.SM&version=10.0.0.1
#tool nuget:?package=RuoVea.SM&version=10.0.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
RuoVea.ExCrypt
介绍
国密 SM2 SM3 SM4 加密算法、字符串加密拓展
使用示例
1. SM2 非对称加密示例
// 生成SM2密钥对
var (publicKey, privateKey) = SMEncryption.SM2GenerateKeyPair();
Console.WriteLine($"公钥: {publicKey}");
Console.WriteLine($"私钥: {privateKey}");
// SM2加密
string plainText = "Hello, SM2加密测试!";
string encrypted = SMEncryption.SM2Encrypt(plainText, publicKey);
Console.WriteLine($"加密结果: {encrypted}");
// SM2解密
string decrypted = SMEncryption.SM2Decrypt(encrypted, privateKey);
Console.WriteLine($"解密结果: {decrypted}");
2. SM3 哈希算法示例
// SM3哈希计算
string data = "Hello, SM3哈希测试!";
string hash = SMEncryption.SM3Hash(data);
Console.WriteLine($"SM3哈希值: {hash}");
// 验证哈希
bool isValid = SMEncryption.SM3Verify(data, hash);
Console.WriteLine($"哈希验证结果: {isValid}");
3. SM4 对称加密示例
// 生成SM4密钥和IV
string sm4Key = SMEncryption.SM4GenerateKey(true); // 16进制格式
string sm4IV = SMEncryption.SM4GenerateIV(true); // 16进制格式
Console.WriteLine($"SM4密钥: {sm4Key}");
Console.WriteLine($"SM4 IV: {sm4IV}");
// SM4 ECB模式加密解密
string text = "Hello, SM4 ECB模式测试!";
string ecbEncrypted = SMEncryption.SM4EncryptECB(text, sm4Key, true);
Console.WriteLine($"ECB加密结果: {ecbEncrypted}");
string ecbDecrypted = SMEncryption.SM4DecryptECB(ecbEncrypted, sm4Key, true);
Console.WriteLine($"ECB解密结果: {ecbDecrypted}");
// SM4 CBC模式加密解密
string cbcEncrypted = SMEncryption.SM4EncryptCBC(text, sm4Key, sm4IV, true);
Console.WriteLine($"CBC加密结果: {cbcEncrypted}");
string cbcDecrypted = SMEncryption.SM4DecryptCBC(cbcEncrypted, sm4Key, sm4IV, true);
Console.WriteLine($"CBC解密结果: {cbcDecrypted}");
// 使用默认密钥的简化方式
string defaultEncrypted = SMEncryption.SM4EncryptECB(text);
Console.WriteLine($"默认密钥加密结果: {defaultEncrypted}");
string defaultDecrypted = SMEncryption.SM4DecryptECB(defaultEncrypted);
Console.WriteLine($"默认密钥解密结果: {defaultDecrypted}");
4. 综合使用场景示例
// 场景:使用SM2加密SM4密钥进行安全传输
// 接收方生成SM2密钥对
var (receiverPubKey, receiverPrivKey) = SMEncryption.SM2GenerateKeyPair();
// 发送方生成SM4会话密钥
string sessionKey = SMEncryption.SM4GenerateKey(true);
string sessionIV = SMEncryption.SM4GenerateIV(true);
// 发送方用SM2加密SM4密钥
string encryptedKey = SMEncryption.SM2Encrypt(sessionKey, receiverPubKey);
// 发送方用SM4加密实际数据
string sensitiveData = "这是一条敏感信息";
string encryptedData = SMEncryption.SM4EncryptCBC(sensitiveData, sessionKey, sessionIV, true);
// 接收方先解密SM4密钥
string decryptedKey = SMEncryption.SM2Decrypt(encryptedKey, receiverPrivKey);
// 接收方再用SM4解密数据
string finalData = SMEncryption.SM4DecryptCBC(encryptedData, decryptedKey, sessionIV, true);
Console.WriteLine($"最终解密结果: {finalData}");
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- Portable.BouncyCastle (>= 1.9.0)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on RuoVea.SM:
Package | Downloads |
---|---|
RuoVea.ExSugar
Sqlsugar扩展 快速注入,支持简体中文、繁体中文、粤语、日语、法语、英语.使用方式:service.AddSqlsugar();继承RestFulLog 重写异常日志,操作日志,差异日志 |
|
RuoVea.ExPws
集成加密工具类 AES、 Base64、DESC、HMACSHA1、HMACSHA256、HMACSHA384、HMACSHA512、MD5、JsMD5、RSA、SHA1、SHA256、SHA384、、SHA512 加密算法; 字符串加密拓展 ToMD5Encrypt、ToAESEncrypt、ToAESDecrypt、ToDESCEncrypt、ToDESCDecrypt、ToRSAEncrpyt、ToRSADecrypt,支持简体中文、繁体中文、粤语、日语、法语、英语. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
10.0.0.1 | 514 | 7/25/2025 |
10.0.0 | 474 | 7/25/2025 |
9.0.0 | 464 | 7/25/2025 |
8.0.0.1 | 1,666 | 7/18/2025 |
8.0.0 | 1,490 | 8/28/2024 |
7.0.0.1 | 1,971 | 7/18/2025 |
7.0.0 | 1,567 | 8/28/2024 |
6.0.1.2 | 2,556 | 7/18/2025 |
6.0.1.1 | 6,192 | 8/28/2024 |
6.0.1 | 955 | 3/12/2023 |
6.0.0 | 368 | 3/8/2023 |
5.0.0.1 | 163 | 7/18/2025 |
5.0.0 | 347 | 9/11/2024 |