sm2

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 4, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesToPrivateKey

func BytesToPrivateKey(data []byte) (*sm2.PrivateKey, error)

BytesToPrivateKey 从字节恢复私钥

func BytesToPublicKey

func BytesToPublicKey(data []byte) (*ecdsa.PublicKey, error)

BytesToPublicKey 从字节恢复公钥(支持非压缩格式 65字节 或 64字节纯坐标)

func Decrypt

func Decrypt(privateKey *sm2.PrivateKey, ciphertext []byte) ([]byte, error)

Decrypt 使用私钥解密数据

func DecryptWithBytes

func DecryptWithBytes(privateKeyBytes, ciphertext []byte) ([]byte, error)

DecryptWithBytes 使用私钥字节解密数据

func Encrypt

func Encrypt(publicKey *ecdsa.PublicKey, plaintext []byte) ([]byte, error)

Encrypt 使用公钥加密数据 (ASN.1 编码输出)

func EncryptWithBytes

func EncryptWithBytes(publicKeyBytes, plaintext []byte) ([]byte, error)

EncryptWithBytes 使用公钥字节加密数据

func GenerateKeyPair

func GenerateKeyPair() (*sm2.PrivateKey, error)

GenerateKeyPair 生成 SM2 密钥对

func GenerateKeyPairBytes

func GenerateKeyPairBytes() (encryption.EncryptionPair, error)

GenerateKeyPairBytes 生成 SM2 密钥对并返回字节形式

func HexToPrivateKey

func HexToPrivateKey(hexStr string) (*sm2.PrivateKey, error)

HexToPrivateKey 从十六进制字符串恢复私钥

func HexToPublicKey

func HexToPublicKey(hexStr string) (*ecdsa.PublicKey, error)

HexToPublicKey 从十六进制字符串恢复公钥

func PrivateKeyToBytes

func PrivateKeyToBytes(privateKey *sm2.PrivateKey) []byte

PrivateKeyToBytes 将私钥序列化为字节 (32字节)

func PrivateKeyToHex

func PrivateKeyToHex(privateKey *sm2.PrivateKey) string

PrivateKeyToHex 将私钥序列化为十六进制字符串

func PublicKeyToBytes

func PublicKeyToBytes(publicKey *ecdsa.PublicKey) []byte

PublicKeyToBytes 将公钥序列化为字节 (65字节: 04 + X + Y 非压缩格式)

func PublicKeyToHex

func PublicKeyToHex(publicKey *ecdsa.PublicKey) string

PublicKeyToHex 将公钥序列化为十六进制字符串

func Sign

func Sign(privateKey *sm2.PrivateKey, msg []byte) ([]byte, error)

Sign 使用私钥对消息签名

func SignWithBytes

func SignWithBytes(privateKeyBytes, msg []byte) ([]byte, error)

SignWithBytes 使用私钥字节对消息签名

func Verify

func Verify(publicKey *ecdsa.PublicKey, msg, signature []byte) bool

Verify 使用公钥验证签名

func VerifyWithBytes

func VerifyWithBytes(publicKeyBytes, msg, signature []byte) (bool, error)

VerifyWithBytes 使用公钥字节验证签名

Types

type SM2Signer

type SM2Signer struct {
	// contains filtered or unexported fields
}

SM2Signer SM2 签名器

func NewSM2Signer

func NewSM2Signer(privateKey *sm2.PrivateKey) *SM2Signer

NewSM2Signer 创建 SM2 签名器

func (*SM2Signer) Sign

func (s *SM2Signer) Sign(msg []byte) ([]byte, error)

type SM2Verifier

type SM2Verifier struct {
	// contains filtered or unexported fields
}

SM2Verifier SM2 验签器

func NewSM2Verifier

func NewSM2Verifier(publicKey *ecdsa.PublicKey) *SM2Verifier

NewSM2Verifier 创建 SM2 验签器

func (*SM2Verifier) Verify

func (v *SM2Verifier) Verify(msg, signature []byte) (bool, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL