Documentation
¶
Index ¶
- Constants
- Variables
- func P256() elliptic.Curve
- type PrivateKey
- type PublicKey
- type SM2
- func (s *SM2) DecodePrivateKey(data []byte) (*PrivateKey, error)
- func (s *SM2) DecodePublicKey(data []byte) (*PublicKey, error)
- func (s *SM2) Decrypt(priv *PrivateKey, ciphertext []byte) ([]byte, error)
- func (s *SM2) Encrypt(pub *PublicKey, plaintext []byte, random io.Reader) ([]byte, error)
- func (s *SM2) GenerateKey(random io.Reader) (*PrivateKey, error)
- func (s *SM2) Sign(priv *PrivateKey, digest []byte) ([]byte, error)
- func (s *SM2) SignWithId(priv *PrivateKey, msg []byte, uid []byte) ([]byte, error)
- func (s *SM2) Verify(pub *PublicKey, digest []byte, signature []byte) bool
- func (s *SM2) VerifyWithId(pub *PublicKey, msg []byte, signature []byte, uid []byte) bool
Constants ¶
View Source
const ( // SM2使用256位曲线,私钥为32字节 PrivateKeySize = 32 // SM2公钥为65字节(压缩格式为33字节) PublicKeySize = 65 // 签名结果为64字节(r和s各32字节) SignatureSize = 64 )
密钥大小(字节)
Variables ¶
View Source
var ( ErrInvalidPrivateKey = errors.New("sm2: 无效的私钥") ErrInvalidPublicKey = errors.New("sm2: 无效的公钥") ErrInvalidSignature = errors.New("sm2: 无效的签名") ErrInvalidCiphertext = errors.New("sm2: 无效的密文") ErrDecryptionFailed = errors.New("sm2: 解密失败") ErrVerificationFailed = errors.New("sm2: 验证失败") )
错误定义
Functions ¶
Types ¶
type PrivateKey ¶
PrivateKey 表示SM2私钥
func (*PrivateKey) EncodePrivateKey ¶
func (priv *PrivateKey) EncodePrivateKey() []byte
EncodePrivateKey 将私钥编码为字节流
type SM2 ¶
type SM2 struct {
// contains filtered or unexported fields
}
SM2 封装SM2算法功能
func (*SM2) DecodePrivateKey ¶
func (s *SM2) DecodePrivateKey(data []byte) (*PrivateKey, error)
DecodePrivateKey 从字节流解码私钥
func (*SM2) DecodePublicKey ¶
DecodePublicKey 从字节流解码公钥
func (*SM2) Decrypt ¶
func (s *SM2) Decrypt(priv *PrivateKey, ciphertext []byte) ([]byte, error)
Decrypt 使用SM2算法解密密文
func (*SM2) GenerateKey ¶
func (s *SM2) GenerateKey(random io.Reader) (*PrivateKey, error)
GenerateKey 生成SM2密钥对
func (*SM2) Sign ¶
func (s *SM2) Sign(priv *PrivateKey, digest []byte) ([]byte, error)
Sign 使用SM2算法签名消息
func (*SM2) SignWithId ¶
SignWithId 使用SM2算法和用户标识进行数字签名
Click to show internal directories.
Click to hide internal directories.