TrustyPay.Crypto 0.0.13

dotnet add package TrustyPay.Crypto --version 0.0.13
NuGet\Install-Package TrustyPay.Crypto -Version 0.0.13
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="TrustyPay.Crypto" Version="0.0.13" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TrustyPay.Crypto --version 0.0.13
#r "nuget: TrustyPay.Crypto, 0.0.13"
#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 TrustyPay.Crypto as a Cake Addin
#addin nuget:?package=TrustyPay.Crypto&version=0.0.13

// Install TrustyPay.Crypto as a Cake Tool
#tool nuget:?package=TrustyPay.Crypto&version=0.0.13

TrustyPay.Crypto

Nuget

What is TrustyPay.Crypto?

TrustyPay.Crypto is a library about cryptographic algorithm, which includes RSA/SM2 and AES/SM4. In addition, it defines a http client abstract class which provides GetAsync and PostAsync methods. These methods may wrap request or response with different encryption or signature simply. Some libraries, such as TrustyPay.Crypto.Banks.ICBC, TrustyPay.Crypto.Banks.CMB, have extended the abstract class to meet the requirements of bank api.

Installing

using .net cli:

dotnet add package TrustyPay.Crypto

import namespace:

using TrustyPay.Crypto;

How to use

  • AES class

    1. Secret key generation
      // generate 128 bit secret key.
      var secretKey = AES.GenerateSecretKey(KeySize.AES128);
      
    2. Encryption
      var aes = new AES(secretKey.Key, secretKey.IV);
      var cipherText = aes.Encrypt("hello_world!!!".FromUTF8String()).ToBase64();
      
    3. Decryption
      var aes = new AES(secretKey.Key, secretKey.IV);
      var plainText = aes.Decrypt("<the above cipher text>".FromBase64()).ToUTF8String();
      
  • SM4 class

    1. Secret key generation
      // generate 128 bit secret key.
      var secretKey = SM4.GenerateSecretKey();
      
    2. Encryption
      var sm4 = new SM4(secretKey.Key, secretKey.IV);
      var cipherText = sm4.Encrypt(
          "hello_world!!!".FromUTF8String()).ToBase64();
      
    3. Decryption
      var sm4 = new SM4(secretKey.Key, secretKey.IV);
      var plainText = sm4.Decrypt(
          "<the above cipher text>".FromBase64()).ToUTF8String();
      
  • RSA class

    1. Private/Public key generation

      // key size is 2048
      var keyPair = RSA.GenerateKeyPair(
          RSA.PrivateKey.PrivateKeyFormat.Pkcs1, RSA.KeySize.RSA2048);
      
    2. Encryption

      using System.Security.Cryptography;
      
      var rsa = new RSA(keyPair, RSAEncryptionPadding.Pkcs1);
      var cipherText = rsa.Encrypt(
          "hello_world!!!".FromUTF8String()).ToBase64();
      
    3. Decryption

      using System.Security.Cryptography;
      
      var rsa = new RSA(keyPair, RSAEncryptionPadding.Pkcs1);
      var plainText = rsa.Decrypt(
          "<the above cipher text>".FromBase64()).ToUTF8String();
      
    4. Sign

      using System.Security.Cryptography;
      
      var rsa = new RSA(keyPair, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
      var signatureText = rsa.Sign(
          "hello_world!!!".FromUTF8String()).ToBase64();
      
    5. Verification

      using System.Security.Cryptography;
      
      var rsa = new RSA(keyPair, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
      var ok = rsa.Verify(
          "hello_world!!!".FromUTF8String(), "<the above signature text>".FromBase64());
      
  • SM2 class

    1. Private/Public key generation

      var keyPair = SM2.GenerateKeyPair();
      
    2. Encryption

      var sm2 = new SM2(keyPair, CipherFormat.C1C2C3);
      var cipherText = sm2.Encrypt(
          "hello_world!!!".FromUTF8String()).ToBase64();
      
    3. Decryption

      var sm2 = new SM2(keyPair, CipherFormat.C1C2C3);
      var plainText = sm2.Decrypt(
          "<the above cipher text>".FromBase64()).ToUTF8String();
      
    4. Sign

      var sm2 = new SM2(keyPair);
      var signatureText = sm2.Sign(
          "hello_world!!!".FromUTF8String()).ToBase64();
      
    5. Verification

      
      var rsa = new SM2(keyPair);
      var ok = sm2.Verify(
          "hello_world!!!".FromUTF8String(), 
          "<the above signature text>".FromBase64());
      
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  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 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.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on TrustyPay.Crypto:

Package Downloads
TrustyPay.Crypto.Banks.CMB

This is a http client for bank 'CMB' interface with SM2/SM4.

TrustyPay.Crypto.Banks.ICBC

This is a http client for bank 'ICBC' interface with RSA2.

TrustyPay.Crypto.Authentication

This is an aspnet core middleware for authentication.

TrustyPay.Crypto.Sdks.DotNet

This is an dotnet client.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.0.13 429 2/25/2023
0.0.12 199 2/25/2023
0.0.11 6,889 10/8/2022
0.0.10 428 9/28/2022
0.0.9 362 9/26/2022
0.0.8 509 7/21/2022
0.0.7 809 7/20/2022
0.0.6 1,183 7/15/2022
0.0.4 969 6/25/2022
0.0.3 689 6/10/2022
0.0.2 665 6/6/2022
0.0.1 708 6/1/2022