Encrypt.Library 2.0.6.7

There is a newer version of this package available.
See the version list below for details.
dotnet add package Encrypt.Library --version 2.0.6.7                
NuGet\Install-Package Encrypt.Library -Version 2.0.6.7                
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="Encrypt.Library" Version="2.0.6.7" />                
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.7                
#r "nuget: Encrypt.Library, 2.0.6.7"                
#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 Encrypt.Library as a Cake Addin
#addin nuget:?package=Encrypt.Library&version=2.0.6.7

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

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 Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 was computed.  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 was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on Encrypt.Library:

Package Downloads
TJC.Cyclops.Common

企服版框架工具类项目

TJC.Cyclops.Wechat

企服版框架中微信对接相关业务核心项目

TJC.Cyclops.UCenter

企服版框架中Discuz的UCenter用户同步注册、登录

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.1.3.3 4,640 10/28/2024
2.1.3.2 1,704 9/14/2024
2.1.3.1 6,633 7/26/2023
2.1.2.9 844 2/3/2023
2.0.6.8 450 9/1/2022
2.0.6.7 422 9/1/2022
2.0.6.6 468 8/12/2022
2.0.1.8 481 8/3/2022
1.0.0.3 456 7/29/2022
1.0.0.2 447 7/29/2022
1.0.0.1 452 7/29/2022
1.0.0 457 7/29/2022

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