欢迎来到 Dotnet 工具箱!在这里,你可以发现各种令人惊喜的开源项目!
公众号内回复 上海找工作
获取 2023 上海 .NET 公司列表。
.NETCore.Encrypt 是使用 C# 开发的开源的加解密工具,封装了常见的算法,包含 AES,RSA,MD5,SAH1,SAH256,SHA384,SHA512等。
通过 Nuget 或 .NET CLI 安装。
Install-Package NETCore.Encrypt -Version 2.1.1
dotnet add package NETCore.Encrypt --version 2.1.1
AES
Create AES Key
var aesKey = EncryptProvider.CreateAesKey();
var key = aesKey.Key;
var iv = aesKey.IV;
AES encrypt
AES encrypt without iv (ECB mode)
var srcString = "aes encrypt";
var encrypted = EncryptProvider.AESEncrypt(srcString, key);
AES encrypt with iv (CBC mode)
var srcString = "aes encrypt";
var encrypted = EncryptProvider.AESEncrypt(srcString, key, iv);
AES encrypt bytes with iv (CBC mode)
var srcBytes = new byte[]{xxx};
var encryptedBytes = EncryptProvider.AESEncrypt(srcBytes, key, iv);
**ASE decrypt **
AES decrypt without iv (ECB mode)
var encryptedStr = "xxxx";
var decrypted = EncryptProvider.AESDecrypt(encryptedStr, key);
AES decrypt with iv (CBC mode)
var encryptedStr = "xxxx";
var decrypted = EncryptProvider.AESDecrypt(encryptedStr, key, iv);
AES decrypt bytes with iv (CBC mode)
var encryptedBytes = new byte[]{xxx};
var decryptedBytes = EncryptProvider.AESDecrypt(encryptedBytes, key, iv);
DES 加解密
Create DES Key
//des key length is 24 bit
var desKey = EncryptProvider.CreateDesKey();
Create DES Iv 【NEW】
//des iv length is 8 bit
var desIv = EncryptProvider.CreateDesIv();
DES encrypt (ECB mode)
var srcString = "des encrypt";
var encrypted = EncryptProvider.DESEncrypt(srcString, key);
DES encrypt bytes (ECB mode)
var srcBytes = new byte[]{xxx};
var decryptedBytes = EncryptProvider.DESEncrypt(srcBytes, key);
DES decrypt (ECB mode)
var encryptedStr = "xxxx";
var decrypted = EncryptProvider.DESDecrypt(encryptedStr, key);
DES decrypt bytes (ECB mode)
var encryptedBytes = new byte[]{xxx};
var decryptedBytes = EncryptProvider.DESDecrypt(encryptedBytes, key);
DES encrypt bytes with iv (CBC mode)【NEW】
var srcBytes = new byte[]{xxx};
var encrypted = EncryptProvider.DESEncrypt(srcBytes, key, iv);
DES decrypt bytes with iv (CBC mode)【NEW】
var encryptedBytes = new byte[]{xxx};
var encrypted = EncryptProvider.DESDecrypt(encryptedBytes, key, iv);
HMAC
HMAC-MD5
var key="xxx";
var srcString = "hmac md5 hash";
var hashed = EncryptProvider.HMACMD5(srcString,key);
HMAC-SHA1
var key="xxx";
var srcString = "hmac sha hash";
var hashed = EncryptProvider.HMACSHA1(srcString,key);
HMAC-SHA256
var key="xxx";
var srcString = "hmac sha hash";
var hashed = EncryptProvider.HMACSHA256(srcString,key);
HMAC-SHA384
var key="xxx";
var srcString = "hmac sha hash";
var hashed = EncryptProvider.HMACSHA384(srcString,key);
HMAC-SHA512
var key="xxx";
var srcString = "hmac sha hash";
var hashed = EncryptProvider.HMACSHA512(srcString,key);
Base64
Base64Encrypt
var srcString = "base64 string";
var hashed = EncryptProvider.Base64Encrypt(srcString); //default encoding is UTF-8
var srcString = "base64 string";
var hashed = EncryptProvider.Base64Encrypt(srcString,Encoding.ASCII);
Base64Decrypt
var encryptedStr = "xxxxx";
var strValue = EncryptProvider.Base64Decrypt(encryptedStr); //default encoding is UTF-8
var encryptedStr = "xxxxx";
var strValue = EncryptProvider.Base64Decrypt(encryptedStr,Encoding.ASCII);
https://github.com/myloveCc/NETCore.Encrypt
公众号内回复 上海找工作
获取 2023 上海 .NET 公司列表。