Encrypt.Library 2.0.6.8

.NET Standard 2.1
NuGet\Install-Package Encrypt.Library -Version 2.0.6.8
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.
dotnet add package Encrypt.Library --version 2.0.6.8
<PackageReference Include="Encrypt.Library" Version="2.0.6.8" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Encrypt.Library --version 2.0.6.8
#r "nuget: Encrypt.Library, 2.0.6.8"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Encrypt.Library as a Cake Addin
#addin nuget:?package=Encrypt.Library&version=2.0.6.8

// Install Encrypt.Library as a Cake Tool
#tool nuget:?package=Encrypt.Library&version=2.0.6.8

NuGet NET 6.0 NetStandard 2.1 license

NETCore encrypt and decrypt tool,Include AES,RSA,MD5,SAH1,SAH256,SHA384,SHA512 and more

To install NETCore.Encrypt, run the following command in the Package Manager Console

Package Manager

Install-Package Encrypt.Library -Version 2.0.6.6

.NET CLI

dotnet add package Encrypt.Library -Version 2.0.6.6

PackageReference

<PackageReference Include="Encrypt.Library" Version="1.0.0.3" />

Easy to use with Encrypt.Library

AES

Create AES Key
var aesKey = AESUtil.Key;

var key = aesKey.Key;
var iv = aesKey.IV;
AES encrypt
  • AES encrypt without iv (ECB mode)

    var srcString = "aes encrypt";
    var encrypted = AESUtil.Encrypt(srcString, key);
    
    
  • AES encrypt with iv (CBC mode)

    var srcString = "aes encrypt";
    var encrypted = AESUtil.Encrypt(srcString, key, iv);
    
    
  • AES encrypt bytes with iv (CBC mode)

    var srcBytes = new byte[]{xxx};
    var encryptedBytes = AESUtil.Encrypt(srcBytes, key, iv);
    
    
ASE decrypt
  • AES decrypt without iv (ECB mode)

    var encryptedStr = "xxxx";
    var decrypted = AESUtil.Decrypt(encryptedStr, key);
    
  • AES decrypt with iv (CBC mode)

    var encryptedStr = "xxxx";
    var decrypted = AESUtil.Decrypt(encryptedStr, key, iv);
    
  • AES decrypt bytes with iv (CBC mode)

    var encryptedBytes =  new byte[]{xxx};
    var decryptedBytes = AESUtil.Decrypt(encryptedBytes, key, iv);
    

DES

  • Create DES Key
    
    //des key length is 24 bit
    var desKey = DESUtil.Key;
    
    
  • Create DES Iv 【NEW】
    
    //des iv length is 8 bit
    var desIv = DESUtil.Iv;
    
    
  • DES encrypt (ECB mode)
    var srcString = "des encrypt";
    var encrypted = DESUtil.Encrypt(srcString, key);
    
  • DES encrypt bytes (ECB mode)
    var srcBytes =  new byte[]{xxx};
    var decryptedBytes = DESUtil.Encrypt(srcBytes, key);
    
  • DES decrypt (ECB mode)
    var encryptedStr = "xxxx";
    var decrypted = DESUtil.Decrypt(encryptedStr, key);
    
  • DES decrypt bytes (ECB mode)
    var encryptedBytes =  new byte[]{xxx};
    var decryptedBytes = DESUtil.Decrypt(encryptedBytes, key);
    
  • DES encrypt bytes with iv (CBC mode)【NEW】
    var srcBytes =  new byte[]{xxx};
    var encrypted = DESUtil.Encrypt(srcBytes, key, iv);
    
  • DES decrypt bytes with iv (CBC mode)【NEW】
    var encryptedBytes =  new byte[]{xxx};
    var encrypted = DESUtil.Decrypt(encryptedBytes, key, iv);
    

RSA

  • Create RSA Key with RsaSize
    var rsaKey = RSAUtil.Key;    //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;
    
  • Rsa Sign and Verify method
    string rawStr = "xxx";
    string signStr = RSAUtil.Sign(rawStr, privateKey);
    bool   result = RSAUtil.Verify(rawStr, signStr, publicKey);
    
  • RSA encrypt
    var publicKey = rsaKey.PublicKey;
    var srcString = "rsa encrypt";
    
    
    var encrypted = RSAUtil.Encrypt(publicKey, srcString);
    
    // On mac/linux at version 2.0.5
    var encrypted = RSAUtil.Encrypt(publicKey, srcString, RSAEncryptionPadding.Pkcs1);
    
    
  • RSA decrypt
    var privateKey = rsaKey.PrivateKey;
    var encryptedStr = "xxxx";
    
    var decrypted = RSAUtil.Decrypt(privateKey, encryptedStr);
    
    // On mac/linux at version 2.0.5
    var decrypted = RSAUtil.Decrypt(privateKey, encryptedStr, RSAEncryptionPadding.Pkcs1);
    
  • RSA from string
    var privateKey = rsaKey.PrivateKey;
    RSA rsa = RSAUtil.FromString(privateKey);
    
  • RSA with PEM
    
    //Rsa to pem format key
    
    //PKCS1 pem
    var pkcs1KeyTuple = RSAUtil.GetPem(false);
    var publicPem = pkcs1KeyTuple.publicPem;
    var privatePem = pkcs1KeyTuple.privatePem;
    
    //PKCS8 pem
    var pkcs8KeyTuple = RSAUtil.GetPem(true);
    publicPem = pkcs8KeyTuple.publicPem;
    privatePem = pkcs8KeyTuple.privatePem;
    
    //Rsa encrypt and decrypt with pem key
    
    var rawStr = "xxx";
    var enctypedStr = RSAUtil.EncryptWithPem(pemPublicKey, rawStr);
    var decryptedStr = RSAUtil.DecryptWithPem(pemPrivateKey, enctypedStr);
    
    

MD5


var srcString = "Md5 hash";
var hashed = MD5Util.GetMD5Str(srcString);


var srcString = "Md5 hash";
var hashed = MD5Util.GetMd5Str(srcString);

SHA

  • SHA1
    var srcString = "sha hash";    
    var hashed = SHAUtil.GetSHA1(srcString); 
    
  • SHA256
    var srcString = "sha hash";    
    var hashed = SHAUtil.GetSHA256(srcString); 
    
  • SHA384
    var srcString = "sha hash";    
    var hashed = SHAUtil.GetSHA384(srcString); 
    
  • SHA512
    var srcString = "sha hash";    
    var hashed = SHAUtil.GetSHA512(srcString);
    

HMAC

  • HMAC-MD5
    var key="xxx";
    var srcString = "hmac md5 hash";     
    var hashed = MD5Util.GetHMACMD5(srcString,key);
    
  • HMAC-SHA1
    var key="xxx";
    var srcString = "hmac sha hash";    
    var hashed = SHAUtil.GetSHA1(srcString,key);
    
  • HMAC-SHA256
    var key="xxx";
    var srcString = "hmac sha hash";    
    var hashed = SHAUtil.GetSHA256(srcString,key);
    
  • HMAC-SHA384
    var key="xxx";
    var srcString = "hmac sha hash";    
    var hashed = SHAUtil.GetSHA384(srcString,key);
    
  • HMAC-SHA512
    var key="xxx";
    var srcString = "hmac sha hash";    
    var hashed = SHAUtil.GetSHA512(srcString,key);
    
  • SM3
    byte[] bytes=SM3Util.ToSM3byte("Encrypt.Library");
    

SM2

  • SM2
    byte[] pubkey,privkey;
    SM2Util.GenerateKey(out pubkey, out privkey);
    var bytes = Encoding.UTF8.GetByte("Encrypt.Library");    
    var encrypt = SM2Util.Encrypt(pubkey,privkey,Mode.C1C2C3,bytes);
    var decrypt = SM2Util.Decrypt(pubkey,privkey,Mode.C1C2C3,encrypt);
    

SM4

  • Create SM4 Key
    
    //des key length is 24 bit
    var desKey = SM4Util.Key;
    
    
  • Create SM4 Iv 【NEW】
    
    //des iv length is 8 bit
    var desIv = SM4Util.Iv;
    
    
  • SM4 encrypt (ECB mode)
    var srcString = "sm4 encrypt";
    var encrypted = SM4Util.Encrypt(key, srcString);
    
  • SM4 encrypt bytes (ECB mode)
    var srcBytes =  new byte[]{xxx};
    var decryptedBytes = SM4Util.Encrypt(key, srcBytes);
    
  • SM4 decrypt (ECB mode)
    var encryptedStr = "xxxx";
    var decrypted = SM4Util.Decrypt(key, encryptedStr);
    
  • SM4 decrypt bytes (ECB mode)
    var encryptedBytes =  new byte[]{xxx};
    var decryptedBytes = SM4Util.Decrypt(key, encryptedBytes);
    
  • SM4 encrypt bytes with iv (CBC mode)【NEW】
    var srcBytes =  new byte[]{xxx};
    var encrypted = SM4Util.Encrypt(key, iv, srcBytes);
    
  • SM4 decrypt bytes with iv (CBC mode)【NEW】
    var encryptedBytes =  new byte[]{xxx};
    var encrypted = SM4Util.Decrypt(key, iv, encryptedBytes);
    

LICENSE

MIT License

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.1
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

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
2.0.6.8 62 9/1/2022
2.0.6.7 52 9/1/2022
2.0.6.6 72 8/12/2022
2.0.1.8 68 8/3/2022
1.0.0.3 68 7/29/2022
1.0.0.2 66 7/29/2022
1.0.0.1 63 7/29/2022
1.0.0 69 7/29/2022

Encrypt.Library is a common and quick encryption and decryption tool library