NETCore.Encrypt 中文文档
NETCore encrypt and decrpty tool,Include AES,RSA,MD5,SAH1,SAH256,SHA384,SHA512 and more
To install NETCore.Encrypt, run the following command in the Package Manager Console
Install-Package NETCore.Encrypt -Version 2.0.6
var aseKey = EncryptProvider.CreateAesKey();
var key = aesKey.Key;
var iv = aesKey.IV;
-
AES encrypt without iv
var srcString = "aes encrypt"; var encrypted = EncryptProvider.AESEncrypt(srcString, key);
-
AES encrypt with iv
var srcString = "aes encrypt"; var encrypted = EncryptProvider.AESEncrypt(srcString, key, iv);
-
AES encrypt bytes at version 2.0.6
var srcBytes = new byte[]{xxx}; var encryptedBytes = EncryptProvider.AESEncrypt(srcBytes, key, iv);
-
AES decrypt without iv
var encryptedStr = "xxxx"; var decrypted = EncryptProvider.AESDecrypt(encryptedStr, key);
-
AES decrypt with iv
var encryptedStr = "xxxx"; var decrypted = EncryptProvider.AESDecrypt(encryptedStr, key, iv);
-
AES decrypt bytes at version 2.0.6
var encryptedBytes = new byte[]{xxx}; var decryptedBytes = EncryptProvider.AESDecrypt(encryptedBytes, key, iv);
-
//des key length is 24 bit var desKey = EncryptProvider.CreateDesKey();
-
var srcString = "des encrypt"; var encrypted = EncryptProvider.DESEncrypt(srcString, key);
-
var srcBytes = new byte[]{xxx}; var decryptedBytes = EncryptProvider.DESEncrypt(srcBytes, key);
-
var encryptedStr = "xxxx"; var decrypted = EncryptProvider.DESDecrypt(encryptedStr, key);
-
var encryptedBytes = new byte[]{xxx}; var decryptedBytes = EncryptProvider.DESDecrypt(encryptedBytes, key);
-
public enum RsaSize { R2048=2048, R3072=3072, R4096=4096 }
-
var rsaKey = EncryptProvider.CreateRsaKey(); //default is 2048 // var rsaKey = EncryptProvider.CreateRsaKey(RsaSize.R3072); var publicKey = rsaKey.PublicKey; var privateKey = rsaKey.PrivateKey; var exponent = rsaKey.Exponent; var modulus = rsaKey.Modulus;
-
var publicKey = rsaKey.PublicKey; var srcString = "rsa encrypt"; var encrypted = EncryptProvider.RSAEncrypt(publicKey, srcString); // On mac/linux at version 2.0.5 var encrypted = EncryptProvider.RSAEncrypt(publicKey, srcString, RSAEncryptionPadding.Pkcs1);
-
var privateKey = rsaKey.PrivateKey; var encryptedStr = "xxxx"; var decrypted = EncryptProvider.RSADecrypt(privateKey, encryptedStr); // On mac/linux at version 2.0.5 var decrypted = EncryptProvider.RSADecrypt(privateKey, encryptedStr, RSAEncryptionPadding.Pkcs1);
-
var privateKey = rsaKey.PrivateKey; RSA rsa = EncryptProvider.RSAFromString(privateKey);
var srcString = "Md5 hash";
var hashed = EncryptProvider.Md5(srcString);
var srcString = "Md5 hash";
var hashed = EncryptProvider.Md5(srcString, MD5Length.L16);
-
var srcString = "sha hash"; var hashed = EncryptProvider.Sha1(srcString);
-
var srcString = "sha hash"; var hashed = EncryptProvider.Sha256(srcString);
-
var srcString = "sha hash"; var hashed = EncryptProvider.Sha384(srcString);
-
var srcString = "sha hash"; var hashed = EncryptProvider.Sha512(srcString);
-
var key="xxx"; var srcString = "hmac md5 hash"; var hashed = EncryptProvider.HMACMD5(srcString,key);
-
var key="xxx"; var srcString = "hmac sha hash"; var hashed = EncryptProvider.HMACSHA1(srcString,key);
-
var key="xxx"; var srcString = "hmac sha hash"; var hashed = EncryptProvider.HMACSHA256(srcString,key);
-
var key="xxx"; var srcString = "hmac sha hash"; var hashed = EncryptProvider.HMACSHA384(srcString,key);
-
var key="xxx"; var srcString = "hmac sha hash"; var hashed = EncryptProvider.HMACSHA512(srcString,key);
-
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);
-
var encryptedStr = "xxxxx"; var strValue = EncryptProvider.Base64Decrypt(encryptedStr); //default encoding is UTF-8
var encryptedStr = "xxxxx"; var strValue = EncryptProvider.Base64Decrypt(encryptedStr,Encoding.ASCII);
var hashed="some string".MD5();
var hashed="some string".SHA1();
var key="xxx";
var hashed="some string".HMACSHA1(key);