![]() |
VOOZH | about |
dotnet add package BugFree.Security --version 1.0.250901.1412
NuGet\Install-Package BugFree.Security -Version 1.0.250901.1412
<PackageReference Include="BugFree.Security" Version="1.0.250901.1412" />
<PackageVersion Include="BugFree.Security" Version="1.0.250901.1412" />Directory.Packages.props
<PackageReference Include="BugFree.Security" />Project file
paket add BugFree.Security --version 1.0.250901.1412
#r "nuget: BugFree.Security, 1.0.250901.1412"
#:package BugFree.Security@1.0.250901.1412
#addin nuget:?package=BugFree.Security&version=1.0.250901.1412Install as a Cake Addin
#tool nuget:?package=BugFree.Security&version=1.0.250901.1412Install as a Cake Tool
BugFree.Security 是一个基于 .NET 的安全加密库,覆盖对称加密、非对称加密、哈希/HMAC、国密(SM3/SM4)、数字签名、密钥交换、自签名证书等能力。目标是提供统一、简单、可靠的 API,适用于 .NET 5/6/7/8/9 与 .NET Standard 2.1,兼容常见 Web/服务端场景(含 Razor Pages)。
核心设计要点:
说明:
-### 对称加密
注意:对称加密统一走 SymmetricProvider,密文格式为 算法编号$Base64(负载)。SM4 的 Key 期望 16 字节十六进制(32 个 hex 字符)。
说明:非对称能力统一走 AsymmetricProvider。
说明:HashProvider.ComputeHash 支持链式多算法并内嵌盐,输出格式为 salt$hash$algorithms,Verify 采用恒定时比较。
通过 NuGet 安装(任选一种):
dotnet add package BugFree.Security
using BugFree.Security;
var data = "This is a test string for hashing and encryption.";
var hash = data.ComputeHash(new[] { HashAlgorithm.SHA256 });
var ok = data.Verify(hash);
using BugFree.Security;
var key = "0123456789abcdef"; // 任意口令字符串(AES 等),SM4 请使用 32 个 hex 字符
var plain = "This is a test string for hashing and encryption.";
var cipher = plain.EncryptSymmetric(SymmetricAlgorithm.Aes, key);
var back = cipher.DecryptSymmetric(key); // 解密无需再次传算法,算法编号已包含在密文中
using BugFree.Security;
var plain = "This is a test string for hashing and encryption.";
var keyPair = AsymmetricProvider.GenerateKeyPair(AsymmetricAlgorithm.RSA);
var cipher = plain.EncryptAsymmetric(keyPair.PublicKey, AsymmetricAlgorithm.RSA);
var back = cipher.DecryptAsymmetric(keyPair.PrivateKey);
(算法与密钥需匹配,例如这里用 RSA;也可以换成 ECDSA/DSA 并用对应的密钥对)
using BugFree.Security;
var data = "This is a test string for hashing and encryption.";
var kp = AsymmetricProvider.GenerateKeyPair(AsymmetricAlgorithm.RSA);
var sig = data.Sign(kp.PrivateKey, AsymmetricAlgorithm.RSA);
var ok = data.Verify(sig, kp.PublicKey);
using BugFree.Security;
var a = AsymmetricProvider.GenerateKeyPair(AsymmetricAlgorithm.ECDH);
var b = AsymmetricProvider.GenerateKeyPair(AsymmetricAlgorithm.ECDH);
var s1 = a.PrivateKey.GenerateSharedSecret(b.PublicKey, AsymmetricAlgorithm.ECDH);
var s2 = b.PrivateKey.GenerateSharedSecret(a.PublicKey, AsymmetricAlgorithm.ECDH);
欢迎提交 Issue 或 Pull Request,一起完善算法支持、优化 API/性能与文档示例。
如有问题或建议,请联系邮箱:ligengrong@hotmail.com
| 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 was computed. 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 was computed. 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 BugFree.Security:
| Package | Downloads |
|---|---|
|
BugFree.Configuration
强类型配置框架,支持 Ini/Xml/Json/Yaml 多种格式,可选 AES-GCM 加密与原子写入,支持热重载。 |
|
|
BugFree.Login
Package Description |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.2.2026.614-beta1531 | 170 | 6/14/2026 |
| 1.2.2026.613-beta1546 | 111 | 6/13/2026 |
| 1.2.2026.613-beta1518 | 83 | 6/13/2026 |
| 1.1.2026.121-beta1056 | 164 | 1/21/2026 |
| 1.1.2026.120-beta1359 | 110 | 1/20/2026 |
| 1.1.2026.118-beta1057 | 111 | 1/18/2026 |
| 1.0.250901.1412 | 253 | 9/1/2025 |
| 1.0.250901.1057-beta1057 | 205 | 9/1/2025 |
| 1.0.250817.1009 | 202 | 8/17/2025 |
| 1.0.250817.956 | 262 | 8/17/2025 |
| 1.0.250816.1231 | 173 | 8/16/2025 |
| 1.0.250807.1134-beta1134 | 297 | 8/7/2025 |
| 1.0.250806.1401-beta1401 | 303 | 8/6/2025 |
| 1.0.250802.1238-beta1238 | 117 | 8/2/2025 |
| 1.0.250801.1531-beta1531 | 160 | 8/1/2025 |
| 1.0.2026.115-beta1517 | 154 | 1/15/2026 |
| 1.0.2026.115-beta1314 | 125 | 1/15/2026 |
| 1.0.2025.1224-beta1343 | 265 | 12/24/2025 |
Hash;Asymmetric;GM(SM2、SM3、SM4);Symmetric;