BugFree.Security
1.0.250807.1134-beta1134
This is a prerelease version of BugFree.Security.
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package BugFree.Security --version 1.0.250807.1134-beta1134
NuGet\Install-Package BugFree.Security -Version 1.0.250807.1134-beta1134
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="BugFree.Security" Version="1.0.250807.1134-beta1134" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BugFree.Security" Version="1.0.250807.1134-beta1134" />
<PackageReference Include="BugFree.Security" />
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 BugFree.Security --version 1.0.250807.1134-beta1134
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: BugFree.Security, 1.0.250807.1134-beta1134"
#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 BugFree.Security@1.0.250807.1134-beta1134
#: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=BugFree.Security&version=1.0.250807.1134-beta1134&prerelease
#tool nuget:?package=BugFree.Security&version=1.0.250807.1134-beta1134&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
BugFree.Security
BugFree.Security 是一个基于 .NET 的安全加密库,支持多种对称加密、非对称加密、哈希算法、国密算法(SM2/SM3/SM4)、数字签名、密钥交换等功能。适用于 .NET 5/6/7/8/9 及 .NET Standard 2.1,兼容 Razor Pages 项目。
功能特性
- 对称加密:AES、SM4 等
- 非对称加密:RSA、SM2
- 哈希算法:SHA256、PBKDF2、Argon2、SM3
- 数字签名
- 密钥交换
- 自签名证书生成
安装
通过 NuGet 安装:dotnet add package BugFree.Security
使用示例
1、哈希算法
using BugFree.Security;
var data = "This is a test string for hashing and encryption.";
var hash = data.ComputeHash([HashAlgorithm.MD5]);
var res = data.Verify(hash);
2、对称加密
using BugFree.Security;
var key = "0123456789abcdef"; // 16字节密钥
var plainData = "This is a test string for hashing and encryption.";
var cipherData = plainData.Encrypt(SymmetricAlgorithm.Aes, key);
var res = cipherData.Decrypt(SymmetricAlgorithm.Aes, key);
3、非对称加密
3.1、RSA 加解密
using BugFree.Security;
var plainData = "This is a test string for hashing and encryption.";
var keyPair = AsymmetricProvider.GenerateKeyPair(AsymmetricAlgorithm.RSA);
var cipherText = plainData.EncryptAsymmetric(keyPair.PublicKey, AsymmetricAlgorithm.RSA);
var plainText = cipherText.DecryptAsymmetric(keyPair.PrivateKey);
3.2 签名、验签
using BugFree.Security;
var plainData = "This is a test string for hashing and encryption.";
var keyPair = AsymmetricProvider.GenerateKeyPair(AsymmetricAlgorithm.RSA);
var signature = plainData.Sign(keyPair.PrivateKey, AsymmetricAlgorithm.DSA);
var verify = plainData.Verify(signature, keyPair.PublicKey);
3.3、密钥交换
using BugFree.Security;
var keyPair1 = AsymmetricProvider.GenerateKeyPair(AsymmetricAlgorithm.ECDH);
var keyPair2 = AsymmetricProvider.GenerateKeyPair(AsymmetricAlgorithm.ECDH);
var sharedSecret1 = keyPair1.PrivateKey.GenerateSharedSecret(keyPair2.PublicKey, AsymmetricAlgorithm.ECDH);
var sharedSecret2 = keyPair2.PrivateKey.GenerateSharedSecret(keyPair1.PublicKey, AsymmetricAlgorithm.ECDH);
依赖环境
- .NET 5/6/7/8/9 或 .NET Standard 2.1
贡献
欢迎提交 Issue 或 Pull Request 以完善本项目。
联系方式
如有问题或建议,请联系邮箱:ligengrong@hotmail.com
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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.
-
net8.0
- Konscious.Security.Cryptography.Argon2 (>= 1.3.1)
- NewLife.Core (>= 11.3.2025.101)
- Portable.BouncyCastle (>= 1.9.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on BugFree.Security:
Package | Downloads |
---|---|
BugFree.Configuration
BugFree.Configuration_强类型配置框架:Ini/Xml/Json/Yaml,支持可选加密(AES-GCM)与原子写入 |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
1.0.250901.1412 | 144 | 9/1/2025 |
1.0.250901.1057-beta1057 | 124 | 9/1/2025 |
1.0.250817.1009 | 103 | 8/17/2025 |
1.0.250817.956 | 120 | 8/17/2025 |
1.0.250816.1231 | 64 | 8/16/2025 |
1.0.250807.1134-beta1134 | 207 | 8/7/2025 |
1.0.250806.1401-beta1401 | 216 | 8/6/2025 |
1.0.250802.1238-beta1238 | 36 | 8/2/2025 |
1.0.250801.1531-beta1531 | 83 | 8/1/2025 |
Hash;Asymmetric;GM(SM2、SM3、SM4);Symmetric;