EasilyNET.Security
1.8.4
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 EasilyNET.Security --version 1.8.4
NuGet\Install-Package EasilyNET.Security -Version 1.8.4
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="EasilyNET.Security" Version="1.8.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EasilyNET.Security --version 1.8.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: EasilyNET.Security, 1.8.4"
#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.
// Install EasilyNET.Security as a Cake Addin
#addin nuget:?package=EasilyNET.Security&version=1.8.4
// Install EasilyNET.Security as a Cake Tool
#tool nuget:?package=EasilyNET.Security&version=1.8.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
EasilyNET.Security
一个.Net 中常用的加密算法的封装.降低加密解密的使用复杂度.
目前有的算法:AES,DES,RC4,TripleDES,RSA,SM2,SM3,SM4
支持 RSA XML 结构的 SecurityKey 和 Base64 格式的互转.
本库不是去实现加密算法,而是基于.Net 提供的接口封装,为了方便使用
未经测试的预测,若是遇到了解密乱码,可能是需要引入一个包.
在主项目中添加 System.Text.Encoding.CodePages 库,并在程序入口处添加注册代码. Programe.cs
var builder = WebApplication.CreateBuilder(args);
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
- 新增 SM3 和 SM4,使用案例
SM3
private const string data = "Microsoft";
/// <summary>
/// SM3测试16进制字符串格式
/// </summary>
public void SM3HexString()
{
var byte_data = Sm3Crypt.Crypt(data);
var hex = byte_data.ToHex();
hex.ToUpper().Should().Be("1749CE3E4EF7622F1EBABB52078EC86309CABD5A6073C8A0711BF35E19BA51B8");
}
/// <summary>
/// SM3测试Base64字符串格式
/// </summary>
public void SM3Base64()
{
var byte_data = Sm3Crypt.Crypt(data);
var base64 = byte_data.ToBase64();
base64.ToUpper().Should().Be("F0NOPK73YI8EURTSB47IYWNKVVPGC8IGCRVZXHM6UBG=");
}
SM4
/// <summary>
/// SM4ECB模式加密到Base64格式
/// </summary>
public void Sm4EncryptECBToBase64()
{
const string data = "Microsoft";
// 将原文解析到二进制数组格式
var byte_data = Encoding.UTF8.GetBytes(data);
// 进制格式密钥加密数据
var result = Sm4Crypt.EncryptECB("701d1cc0cfbe7ee11824df718855c0c6", true, byte_data);
// 获取Base64格式的字符串结果
var base64 = result.ToBase64();
// ThRruxZZm1GrHE5KkP4UmQ==
}
/// <summary>
/// SM4ECB模式解密Base64格式到字符串
/// </summary>
public void Sm4DecryptECBTest()
{
// Base64格式的
const string data = "ThRruxZZm1GrHE5KkP4UmQ==";
// 将Base64格式字符串转为 byte[]
var byte_data = Convert.FromBase64String(data);
// 通过16进制格式密钥解密数据
var result = Sm4Crypt.DecryptECB("701d1cc0cfbe7ee11824df718855c0c6", true, byte_data);
// 解析结果获取字符串
var str = Encoding.UTF8.GetString(result);
// Microsoft
}
/// <summary>
/// SM4ECB模式加密到16进制字符串
/// </summary>
public void Sm4EncryptECBToHex16()
{
const string data = "Microsoft";
// 将原文解析到二进制数组格式
var byte_data = Encoding.UTF8.GetBytes(data);
// 使用16位长度的密钥加密
var result = Sm4Crypt.EncryptECB("1cc0cfbe7ee11824", false, byte_data);
// 将结果转为16进制字符串
var hex = result.ToHexString();
// D265DF0510C05FE836D3113B3ACEC714
}
/// <summary>
/// SM4ECB模式解密16进制字符串格式密文
/// </summary>
public void Sm4DecryptECBTest2()
{
const string data = "D265DF0510C05FE836D3113B3ACEC714";
var byte_data = data.FromHex();
var result = Sm4Crypt.DecryptECB("1cc0cfbe7ee11824", false, byte_data);
// 解析结果获取字符串
var str = Encoding.UTF8.GetString(result);
// Microsoft
}
/// <summary>
/// SM4CBC模式加密到Base64格式
/// </summary>
public void Sm4EncryptCBCTest()
{
const string data = "Microsoft";
var byte_data = Encoding.UTF8.GetBytes(data);
var result = Sm4Crypt.EncryptCBC("701d1cc0cfbe7ee11824df718855c0c6", true, "701d1cc0cfbe7ee11824df718855c0c5", byte_data);
var base64 = result.ToBase64();
// Q2iUaMuSHjLvq6GhUQnGTg==
}
/// <summary>
/// SM4CBC模式从Base64解密
/// </summary>
public void Sm4DecryptCBCTest()
{
const string data = "Q2iUaMuSHjLvq6GhUQnGTg==";
var byte_data = Convert.FromBase64String(data);
var result = Sm4Crypt.DecryptCBC("701d1cc0cfbe7ee11824df718855c0c6", true, "701d1cc0cfbe7ee11824df718855c0c5", byte_data);
var str = Encoding.UTF8.GetString(result);
// Microsoft
}
/// <summary>
/// SM4CBC模式加密到16进制字符串
/// </summary>
public void Sm4EncryptCBCTest2()
{
const string data = "Microsoft";
var byte_data = Encoding.UTF8.GetBytes(data);
var result = Sm4Crypt.EncryptCBC("1cc0cfbe7ee11824", false, "1cc0cfbe7ee12824", byte_data);
var hex = result.ToHexString();
// 1BD7A32E49B60B17698AAC9D1E4FEE4A
}
/// <summary>
/// SM4CBC模式从Hex16解密到字符串
/// </summary>
public void Sm4DecryptCBCTest2()
{
const string data = "1BD7A32E49B60B17698AAC9D1E4FEE4A";
var byte_data = data.FromHex();
var result = Sm4Crypt.DecryptCBC("1cc0cfbe7ee11824", false, "1cc0cfbe7ee12824", byte_data);
var str = Encoding.UTF8.GetString(result);
// Microsoft
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- BouncyCastle.Cryptography (>= 2.2.1)
- EasilyNET.Core (>= 1.8.4)
-
net7.0
- BouncyCastle.Cryptography (>= 2.2.1)
- EasilyNET.Core (>= 1.8.4)
-
net8.0
- BouncyCastle.Cryptography (>= 2.2.1)
- EasilyNET.Core (>= 1.8.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
3.24.528.90 | 75 | 5/28/2024 |
3.24.522.84 | 51 | 5/22/2024 |
3.24.512.213 | 53 | 5/12/2024 |
3.24.508.112 | 83 | 5/8/2024 |
2.2024.428.71 | 94 | 4/28/2024 |
2.2024.427.1128 | 85 | 4/27/2024 |
2.2.72 | 93 | 4/14/2024 |
2.2.71 | 73 | 4/12/2024 |
2.2.8 | 71 | 4/26/2024 |
2.2.6 | 77 | 4/10/2024 |
2.2.5 | 93 | 3/26/2024 |
2.2.4 | 96 | 3/25/2024 |
2.2.3 | 90 | 3/24/2024 |
2.2.2 | 86 | 3/21/2024 |
2.2.1 | 99 | 3/20/2024 |
2.2.0 | 92 | 3/13/2024 |
2.1.9 | 95 | 2/21/2024 |
2.1.8 | 96 | 2/18/2024 |
2.1.7 | 86 | 2/16/2024 |
2.1.6 | 91 | 2/14/2024 |
2.1.5 | 85 | 2/14/2024 |
2.1.4 | 93 | 2/9/2024 |
2.1.3 | 90 | 2/8/2024 |
2.1.2 | 57 | 2/5/2024 |
2.1.1.2 | 170 | 12/26/2023 |
2.1.1.1 | 96 | 12/26/2023 |
2.1.1 | 102 | 12/25/2023 |
2.1.0 | 102 | 12/17/2023 |
2.0.11 | 122 | 12/6/2023 |
2.0.1 | 108 | 11/15/2023 |
2.0.0 | 91 | 11/14/2023 |
1.9.1 | 95 | 11/1/2023 |
1.9.0 | 89 | 10/19/2023 |
1.9.0-preview2 | 80 | 10/12/2023 |
1.9.0-preview1 | 70 | 10/12/2023 |
1.8.9 | 110 | 10/11/2023 |
1.8.8 | 102 | 10/11/2023 |
1.8.7-rc2 | 76 | 9/21/2023 |
1.8.7-rc1 | 75 | 9/12/2023 |
1.8.6 | 274 | 8/31/2023 |
1.8.5 | 112 | 8/25/2023 |
1.8.4 | 114 | 8/24/2023 |
1.8.3 | 119 | 8/23/2023 |
1.8.2 | 110 | 8/22/2023 |
1.8.1 | 108 | 8/18/2023 |
1.8.0 | 132 | 8/15/2023 |
1.7.9 | 125 | 8/11/2023 |
1.7.8 | 131 | 8/11/2023 |
1.7.7 | 127 | 8/10/2023 |
1.7.6 | 128 | 8/9/2023 |
1.7.5 | 125 | 8/9/2023 |
1.7.4 | 151 | 8/3/2023 |
1.7.3 | 109 | 8/1/2023 |
1.7.2 | 117 | 7/31/2023 |
1.7.1 | 108 | 7/27/2023 |
1.7.0 | 138 | 7/25/2023 |
1.6.9 | 127 | 7/25/2023 |
1.6.8 | 134 | 7/24/2023 |
1.6.7 | 127 | 7/20/2023 |
1.6.6 | 118 | 7/19/2023 |
1.6.5 | 110 | 7/19/2023 |
1.6.4 | 119 | 7/17/2023 |
1.6.3 | 118 | 7/17/2023 |
1.6.2 | 116 | 7/12/2023 |
1.6.1 | 128 | 6/30/2023 |
1.6.0 | 119 | 6/26/2023 |
1.5.9 | 119 | 6/22/2023 |
1.5.8 | 124 | 6/15/2023 |
1.5.7.1 | 124 | 6/14/2023 |
1.5.7 | 122 | 6/14/2023 |
1.5.6.2 | 129 | 6/7/2023 |
1.5.6.1 | 146 | 6/7/2023 |
1.5.6 | 130 | 6/7/2023 |
1.5.5.2 | 120 | 5/26/2023 |
1.5.5.1 | 124 | 5/26/2023 |
1.5.5 | 126 | 5/26/2023 |
1.5.4.4 | 129 | 5/25/2023 |
1.5.4.3 | 127 | 5/23/2023 |
1.5.4.2 | 131 | 5/17/2023 |
1.5.4.1 | 127 | 5/16/2023 |
1.5.4 | 150 | 5/11/2023 |
1.5.3 | 148 | 5/11/2023 |
1.5.2 | 141 | 5/10/2023 |
1.5.1 | 141 | 5/10/2023 |
1.5.0 | 151 | 5/6/2023 |
1.4.0 | 140 | 5/5/2023 |
1.3.9 | 162 | 4/23/2023 |
1.3.8.6 | 154 | 4/23/2023 |
1.3.8.5 | 160 | 4/21/2023 |
1.3.8.1 | 170 | 4/12/2023 |
1.3.8 | 172 | 4/11/2023 |
1.3.7 | 170 | 4/9/2023 |
1.3.6.3 | 192 | 4/1/2023 |
1.3.6.2 | 189 | 3/31/2023 |
1.3.6.1 | 186 | 3/31/2023 |
1.3.6 | 186 | 3/31/2023 |
1.3.5 | 182 | 3/30/2023 |
1.3.4.1 | 199 | 3/29/2023 |
1.3.4 | 182 | 3/28/2023 |
1.3.3 | 188 | 3/28/2023 |
1.3.2 | 199 | 3/26/2023 |
1.3.1 | 201 | 3/22/2023 |
1.3.0 | 195 | 3/21/2023 |
1.2.0 | 210 | 3/21/2023 |
1.1.0 | 219 | 3/17/2023 |
1.0.9 | 209 | 3/16/2023 |