Table of Contents

Class Sm4CryptoProvider

Namespace
Apq.Cfg.Crypto.Providers
Assembly
Apq.Cfg.Crypto.dll

SM4 国密算法加密提供者(使用 BouncyCastle 实现)

public class Sm4CryptoProvider : ICryptoProvider, IDisposable
Inheritance
Sm4CryptoProvider
Implements
Inherited Members

Remarks

性能优化:

  1. 使用静态 SecureRandom 实例避免重复创建
  2. 使用 ArrayPool 减少内存分配

Constructors

Sm4CryptoProvider(byte[], Sm4Mode)

public Sm4CryptoProvider(byte[] key, Sm4Mode mode = Sm4Mode.CBC)

Parameters

key byte[]
mode Sm4Mode

Sm4CryptoProvider(string, Sm4Mode)

public Sm4CryptoProvider(string base64Key, Sm4Mode mode = Sm4Mode.CBC)

Parameters

base64Key string
mode Sm4Mode

Methods

Decrypt(string)

解密密文

public string Decrypt(string cipherText)

Parameters

cipherText string

密文(Base64 编码)

Returns

string

明文

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

Encrypt(string)

加密明文

public string Encrypt(string plainText)

Parameters

plainText string

明文

Returns

string

密文(Base64 编码)