![]() |
VOOZH | about |
dotnet add package Smart.Security --version 4.1.6
NuGet\Install-Package Smart.Security -Version 4.1.6
<PackageReference Include="Smart.Security" Version="4.1.6" />
<PackageVersion Include="Smart.Security" Version="4.1.6" />Directory.Packages.props
<PackageReference Include="Smart.Security" />Project file
paket add Smart.Security --version 4.1.6
#r "nuget: Smart.Security, 4.1.6"
#:package Smart.Security@4.1.6
#addin nuget:?package=Smart.Security&version=4.1.6Install as a Cake Addin
#tool nuget:?package=Smart.Security&version=4.1.6Install as a Cake Tool
<a name="english"></a>
Smart.Security is a .NET security helper library built on .NET cryptography APIs and BouncyCastle. It provides AES, RSA, SM2, SM3, SM4, hash, HMAC, password salt/hash, file hash, and secure random helpers. It supports .NET 8, 9, and 10.
dotnet add package Smart.Security
using Smart.Security;
var key = SmartAESCipher.GenerateKey();
string cipherText = SmartAESCipher.Encrypt("Hello World", key.Key, key.IV);
string plainText = SmartAESCipher.Decrypt(cipherText, key.Key, key.IV);
using Smart.Security;
var keyPair = SmartRSACipher.GenerateRSAKeyPair(2048);
byte[] data = Encoding.UTF8.GetBytes("Secret Message");
byte[] cipherBytes = SmartRSACipher.Encrypt(keyPair.Public, data);
byte[] plainBytes = SmartRSACipher.Decrypt(keyPair.Private, cipherBytes);
byte[] signature = SmartRSACipher.Sign(keyPair.Private, data);
bool valid = SmartRSACipher.VerifySign(keyPair.Public, data, signature);
byte[] sm3 = SmartSM3Hash.SM3Hash(Encoding.UTF8.GetBytes("Data to hash"));
var sm4Key = SmartSM4Cipher.GenerateKey();
string sm4Cipher = SmartSM4Cipher.Encrypt("SM4 message", sm4Key.Base64Key, sm4Key.Base64IV);
string sm4Plain = SmartSM4Cipher.Decrypt(sm4Cipher, sm4Key.Base64Key, sm4Key.Base64IV);
byte[] sm2Cipher = SmartSM2Cipher.Encrypt(publicKeyBytes, plainBytes);
byte[] sm2Plain = SmartSM2Cipher.Decrypt(privateKeyBytes, sm2Cipher);
byte[] sm2Signature = SmartSM2Cipher.Sign(privateKeyBytes, plainBytes);
bool sm2Valid = SmartSM2Cipher.VerifySign(publicKeyBytes, plainBytes, sm2Signature);
byte[] data = Encoding.UTF8.GetBytes("Data to hash");
string sha256 = SmartHash.SHA256Hash(data);
string sha512 = SmartHash.SHA512Hash(data);
string hmac = SmartHash.HmacSHA256(data, "secret-key");
string md5 = SmartFileHash.MD5Hash(filePath);
string sha256 = await SmartFileHash.SHA256HashAsync(filePath);
SmartPassword generates a Base64 salt and stores a Base64 SHA256 hash of password + salt.
string salt = SmartPassword.GenerateSalt();
string hash = SmartPassword.HashPassword("user_password", salt);
bool valid = SmartPassword.VerifyPassword("user_password", salt, hash);
string base64Key = SmartRandom.GenerateKey(256);
byte[] bytes = SmartRandom.RandomArray(32);
string text = SmartRandom.RandomString(16);
string digits = SmartRandom.RandomNumber(6);
long number = SmartRandom.RandomLong();
<a name="chinese"></a>
Smart.Security 是基于 .NET 密码学 API 和 BouncyCastle 的安全工具库,提供 AES、RSA、SM2、SM3、SM4、哈希、HMAC、密码盐值/哈希、文件哈希和安全随机数等能力,兼容 .NET 8/9/10。
dotnet add package Smart.Security
using Smart.Security;
var key = SmartAESCipher.GenerateKey();
string cipherText = SmartAESCipher.Encrypt("Hello World", key.Key, key.IV);
string plainText = SmartAESCipher.Decrypt(cipherText, key.Key, key.IV);
using Smart.Security;
var keyPair = SmartRSACipher.GenerateRSAKeyPair(2048);
byte[] data = Encoding.UTF8.GetBytes("Secret Message");
byte[] cipherBytes = SmartRSACipher.Encrypt(keyPair.Public, data);
byte[] plainBytes = SmartRSACipher.Decrypt(keyPair.Private, cipherBytes);
byte[] signature = SmartRSACipher.Sign(keyPair.Private, data);
bool valid = SmartRSACipher.VerifySign(keyPair.Public, data, signature);
byte[] sm3 = SmartSM3Hash.SM3Hash(Encoding.UTF8.GetBytes("待哈希数据"));
var sm4Key = SmartSM4Cipher.GenerateKey();
string sm4Cipher = SmartSM4Cipher.Encrypt("SM4 消息", sm4Key.Base64Key, sm4Key.Base64IV);
string sm4Plain = SmartSM4Cipher.Decrypt(sm4Cipher, sm4Key.Base64Key, sm4Key.Base64IV);
byte[] sm2Cipher = SmartSM2Cipher.Encrypt(publicKeyBytes, plainBytes);
byte[] sm2Plain = SmartSM2Cipher.Decrypt(privateKeyBytes, sm2Cipher);
byte[] sm2Signature = SmartSM2Cipher.Sign(privateKeyBytes, plainBytes);
bool sm2Valid = SmartSM2Cipher.VerifySign(publicKeyBytes, plainBytes, sm2Signature);
byte[] data = Encoding.UTF8.GetBytes("待哈希数据");
string sha256 = SmartHash.SHA256Hash(data);
string sha512 = SmartHash.SHA512Hash(data);
string hmac = SmartHash.HmacSHA256(data, "secret-key");
string md5 = SmartFileHash.MD5Hash(filePath);
string sha256 = await SmartFileHash.SHA256HashAsync(filePath);
SmartPassword 会生成 Base64 盐值,并保存 password + salt 的 Base64 SHA256 哈希。
string salt = SmartPassword.GenerateSalt();
string hash = SmartPassword.HashPassword("user_password", salt);
bool valid = SmartPassword.VerifyPassword("user_password", salt, hash);
string base64Key = SmartRandom.GenerateKey(256);
byte[] bytes = SmartRandom.RandomArray(32);
string text = SmartRandom.RandomString(16);
string digits = SmartRandom.RandomNumber(6);
long number = SmartRandom.RandomLong();
Developed by zenglei
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
Showing the top 2 NuGet packages that depend on Smart.Security:
| Package | Downloads |
|---|---|
|
BaseLibrary.ClassLibraryStand
Package Description |
|
|
RL.System.Core
山东瑞隆网络技术有限公司 -API |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 5.0.0-beta.1 | 40 | 6/17/2026 |
| 4.1.6 | 276 | 5/16/2026 |
| 4.1.5 | 222 | 2/11/2026 |
| 4.1.4 | 118 | 2/8/2026 |
| 4.1.3 | 219 | 12/30/2025 |
| 4.1.2 | 259 | 10/15/2025 |
| 4.1.1 | 238 | 7/13/2025 |
| 4.1.0 | 215 | 4/5/2025 |
| 4.0.1 | 303 | 3/23/2025 |
| 4.0.0 | 269 | 3/20/2025 |
| 3.0.2 | 212 | 2/26/2025 |
| 3.0.1 | 228 | 2/15/2025 |
| 3.0.0 | 199 | 2/15/2025 |
| 2.0.2 | 245 | 2/9/2025 |
| 2.0.1 | 216 | 12/7/2024 |
| 1.1.1 | 214 | 12/7/2024 |
| 1.1.0.2 | 240 | 11/11/2024 |