Documentation
¶
Index ¶
- type DecryptFormat
- type DecryptResult
- type EncryptFormat
- type EncryptResult
- type KeyPair
- type Result
- type SM2
- func (s *SM2) Decrypt(privateKey *sm2.PrivateKey, ciphertextByte []byte, format DecryptFormat) *DecryptResult
- func (s *SM2) DecryptFromBase64(privateKey *sm2.PrivateKey, base64Data string, format DecryptFormat) *DecryptResult
- func (s *SM2) DecryptFromBytes(privateKey *sm2.PrivateKey, byteData []byte, format DecryptFormat) *DecryptResult
- func (s *SM2) DecryptFromHex(privateKey *sm2.PrivateKey, hexData string, format DecryptFormat) *DecryptResult
- func (s *SM2) Encrypt(publicKey *sm2.PublicKey, plainTextByte []byte, format EncryptFormat) *EncryptResult
- func (s *SM2) GenerateKeyPair() (*KeyPair, error)
- func (s *SM2) ParsePrivateKeyFromHex(hexKey string) (*sm2.PrivateKey, error)
- func (s *SM2) ParsePrivateKeyFromPem(pemKey string) (*sm2.PrivateKey, error)
- func (s *SM2) ParsePublicKeyFromHex(hexKey string) (*sm2.PublicKey, error)
- func (s *SM2) ParsePublicKeyFromPem(pemKey string) (*sm2.PublicKey, error)
- func (s *SM2) PrivateKeyToHex(privateKey *sm2.PrivateKey) (string, error)
- func (s *SM2) PrivateKeyToPem(privateKey *sm2.PrivateKey) (string, error)
- func (s *SM2) PublicKeyToHex(publicKey *sm2.PublicKey) (string, error)
- func (s *SM2) PublicKeyToPem(publicKey *sm2.PublicKey) (string, error)
- func (s *SM2) SaveKeyPair(keyPair *KeyPair, privateFile, pubFile string) error
- func (s *SM2) SaveKeyPairRaw(privateKeyPem, publicKeyPem, privateFile, pubFile string) error
- func (s *SM2) Sign(privateKey *sm2.PrivateKey, dataByte []byte) *SignResult
- func (s *SM2) VerifyFromBase64(publicKey *sm2.PublicKey, dataByte []byte, base64Signature string) bool
- func (s *SM2) VerifyFromBytes(publicKey *sm2.PublicKey, dataByte, signatureByte []byte) bool
- func (s *SM2) VerifyFromHex(publicKey *sm2.PublicKey, dataByte []byte, hexSignature string) bool
- type SM2Option
- type SignResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EncryptFormat ¶
type EncryptFormat int
EncryptFormat 定义加密格式类型
const ( // C1C3C2 格式 C1C3C2 EncryptFormat = iota // C1C2C3 格式 C1C2C3 // C1C3C2Compressed 压缩格式 C1C3C2Compressed // C1C2C3Compressed 压缩格式 C1C2C3Compressed )
type KeyPair ¶
type KeyPair struct {
PrivateKeyPEM string
PublicKeyPEM string
PrivateKeyHex string
PublicKeyHex string
}
KeyPair 结构体包含PEM和HEX格式的密钥对
type SM2 ¶
type SM2 struct {
// contains filtered or unexported fields
}
SM2 封装了SM2算法相关的操作
func (*SM2) Decrypt ¶
func (s *SM2) Decrypt(privateKey *sm2.PrivateKey, ciphertextByte []byte, format DecryptFormat) *DecryptResult
Decrypt 使用SM2私钥解密数据,支持指定格式
func (*SM2) DecryptFromBase64 ¶
func (s *SM2) DecryptFromBase64(privateKey *sm2.PrivateKey, base64Data string, format DecryptFormat) *DecryptResult
DecryptFromBase64 使用SM2私钥解密Base64编码字符串数据,支持指定格式
func (*SM2) DecryptFromBytes ¶
func (s *SM2) DecryptFromBytes(privateKey *sm2.PrivateKey, byteData []byte, format DecryptFormat) *DecryptResult
DecryptFromBytes 使用SM2私钥解密字节数据,支持指定格式
func (*SM2) DecryptFromHex ¶
func (s *SM2) DecryptFromHex(privateKey *sm2.PrivateKey, hexData string, format DecryptFormat) *DecryptResult
DecryptFromHex 使用SM2私钥解密十六进制字符串数据,支持指定格式
func (*SM2) Encrypt ¶
func (s *SM2) Encrypt(publicKey *sm2.PublicKey, plainTextByte []byte, format EncryptFormat) *EncryptResult
Encrypt 使用SM2公钥加密数据,支持指定格式
func (*SM2) GenerateKeyPair ¶
GenerateKeyPair 生成SM2密钥对
func (*SM2) ParsePrivateKeyFromHex ¶
func (s *SM2) ParsePrivateKeyFromHex(hexKey string) (*sm2.PrivateKey, error)
ParsePrivateKeyFromHex 从十六进制字符串解析私钥
func (*SM2) ParsePrivateKeyFromPem ¶
func (s *SM2) ParsePrivateKeyFromPem(pemKey string) (*sm2.PrivateKey, error)
ParsePrivateKeyFromPem 从PEM格式字符串解析私钥
func (*SM2) ParsePublicKeyFromHex ¶
ParsePublicKeyFromHex 从十六进制字符串解析公钥
func (*SM2) ParsePublicKeyFromPem ¶
ParsePublicKeyFromPem 从PEM格式字符串解析公钥
func (*SM2) PrivateKeyToHex ¶
func (s *SM2) PrivateKeyToHex(privateKey *sm2.PrivateKey) (string, error)
PrivateKeyToHex 将私钥转换为十六进制字符串
func (*SM2) PrivateKeyToPem ¶
func (s *SM2) PrivateKeyToPem(privateKey *sm2.PrivateKey) (string, error)
PrivateKeyToPem 将私钥转换为PEM格式字符串
func (*SM2) PublicKeyToHex ¶
PublicKeyToHex 将公钥转换为十六进制字符串
func (*SM2) PublicKeyToPem ¶
PublicKeyToPem 将公钥转换为PEM格式字符串
func (*SM2) SaveKeyPair ¶
SaveKeyPair 保存密钥对到文件(使用keyPair中的内容,可能已去除header)
func (*SM2) SaveKeyPairRaw ¶
SaveKeyPairRaw 保存原始密钥对到文件(保留完整PEM格式)
func (*SM2) Sign ¶
func (s *SM2) Sign(privateKey *sm2.PrivateKey, dataByte []byte) *SignResult
Sign 使用SM2私钥对数据进行签名
func (*SM2) VerifyFromBase64 ¶
func (s *SM2) VerifyFromBase64(publicKey *sm2.PublicKey, dataByte []byte, base64Signature string) bool
VerifyFromBase64 使用SM2公钥验证Base64编码字符串签名
func (*SM2) VerifyFromBytes ¶
VerifyFromBytes 使用SM2公钥验证签名
type SM2Option ¶
type SM2Option func(*sm2Options)
SM2Option 是用于配置SM2的函数类型
func WithStripHeader ¶
WithStripHeader 设置是否去除公钥和私钥PEM格式的头部和尾部
func WithUnescapeHTML ¶
WithUnescapeHTML 设置是否进行HTML转义处理