SMCrypto.NET 1.1.4

dotnet add package SMCrypto.NET --version 1.1.4
                    
NuGet\Install-Package SMCrypto.NET -Version 1.1.4
                    
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="SMCrypto.NET" Version="1.1.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SMCrypto.NET" Version="1.1.4" />
                    
Directory.Packages.props
<PackageReference Include="SMCrypto.NET" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SMCrypto.NET --version 1.1.4
                    
#r "nuget: SMCrypto.NET, 1.1.4"
                    
#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.
#:package SMCrypto.NET@1.1.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SMCrypto.NET&version=1.1.4
                    
Install as a Cake Addin
#tool nuget:?package=SMCrypto.NET&version=1.1.4
                    
Install as a Cake Tool

China's standards of encryption algorithms(SM2/SM3/SM4)

SM3

var hash_string = SM3.sm3_hash_string("abc");
Debug.Assert(hash_string == "66c7f0f462eeedd9d1f2d46bdc10e4e24167c4875cf2f7a2297da02b8f4ba8e0");

var data = "abc"u8.ToArray();

var hash_bytes = SM3.sm3_hash(data);
Debug.Assert(hash_bytes == "66c7f0f462eeedd9d1f2d46bdc10e4e24167c4875cf2f7a2297da02b8f4ba8e0");

SM2

Generate key pair

var (sk, pk) = SM2.gen_keypair();

Encrypt/Decrypt

var enc_sm2 = SM2.encrypt(data, pk);
var dec_sm2 = SM2.decrypt(enc_sm2, sk);
Debug.Assert(data.SequenceEqual(dec_sm2));

Sign/Verify

var sign = SM2.sign("a@company.com"u8.ToArray(), data, sk);
var verify = SM2.verify("a@company.com"u8.ToArray(), data, sign, pk);
Debug.Assert(verify == 1);

Key Exchange

var id_a = "a@company.com"u8.ToArray();
var (sk_a, pk_a) = SM2.gen_keypair();
var id_b = "b@company.com"u8.ToArray();
var (sk_b, pk_b) = SM2.gen_keypair();
var (a2b, sk_r_a) = SM2.keyexchange_1ab(16, id_a, sk_a);
var (b2a, sk_r_b) = SM2.keyexchange_1ab(16, id_b, sk_b);
var (key_a, _) = SM2.keyexchange_2a(id_a, sk_a, sk_r_a, b2a);
var (key_b, _) = SM2.keyexchange_2b(id_b, sk_b, sk_r_b, a2b);
Debug.Assert(key_a == key_b);

SM4

Encrypt/Decrypt

var key = "1234567812345678"u8.ToArray();
var iv = "0000000000000000"u8.ToArray();

var enc_sm4_ecb = SM4.encrypt_ecb(data, key);
var dec_sm4_ecb = SM4.decrypt_ecb(enc_sm4_ecb, key);
Debug.Assert(data.SequenceEqual(dec_sm4_ecb));

var enc_sm4_cbc = SM4.encrypt_cbc(data, key, iv);
var dec_sm4_cbc = SM4.decrypt_cbc(enc_sm4_cbc, key, iv);
Debug.Assert(data.SequenceEqual(dec_sm4_cbc));
Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net9.0

    • No dependencies.

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
1.1.4 148 6/3/2025