Documentation ¶
Index ¶
- Variables
- func BytesCombine(pBytes ...[]byte) []byte
- func CipherMarshal(data []byte) ([]byte, error)
- func CipherUnmarshal(data []byte) ([]byte, error)
- func Compress(a *PublicKey) []byte
- func Decrypt(priv *PrivateKey, data []byte, mode int) ([]byte, error)
- func DecryptAsn1(pub *PrivateKey, data []byte) ([]byte, error)
- func Encrypt(pub *PublicKey, data []byte, random io.Reader, mode int) ([]byte, error)
- func EncryptAsn1(pub *PublicKey, data []byte, rand io.Reader) ([]byte, error)
- func KeyExchangeA(klen int, ida, idb []byte, priA *PrivateKey, pubB *PublicKey, rpri *PrivateKey, ...) (k, s1, s2 []byte, err error)
- func KeyExchangeB(klen int, ida, idb []byte, priB *PrivateKey, pubA *PublicKey, rpri *PrivateKey, ...) (k, s1, s2 []byte, err error)
- func P256Sm2() elliptic.Curve
- func SignASN1(rand io.Reader, priv *PrivateKey, hash []byte) ([]byte, error)
- func SignDataToSignDigit(sign []byte) (*big.Int, *big.Int, error)
- func SignDigitToSignData(r, s *big.Int) ([]byte, error)
- func Sm2Sign(priv *PrivateKey, signContentDigest, uid []byte, random io.Reader) (r, s *big.Int, err error)
- func Sm2Verify(pub *PublicKey, signContentDigest, uid []byte, r, s *big.Int) bool
- func Verify(pub *PublicKey, hash []byte, r, s *big.Int) bool
- func VerifyASN1(pub *PublicKey, hash, sig []byte) bool
- func WNafReversed(wnaf []int8) []int8
- func ZA(pub *PublicKey, uid []byte) ([]byte, error)
- type PrivateKey
- func (priv *PrivateKey) Decrypt(_ io.Reader, msg []byte, _ crypto.DecrypterOpts) (plaintext []byte, err error)
- func (priv *PrivateKey) DecryptAsn1(data []byte) ([]byte, error)
- func (priv *PrivateKey) Equal(x crypto.PrivateKey) bool
- func (priv *PrivateKey) Public() crypto.PublicKey
- func (priv *PrivateKey) Sign(random io.Reader, signContentDigest []byte, signer crypto.SignerOpts) ([]byte, error)
- type PublicKey
Constants ¶
This section is empty.
Variables ¶
var ( C1C3C2 = 0 C1C2C3 = 1 )
Functions ¶
func BytesCombine ¶
func CipherUnmarshal ¶
CipherUnmarshal sm2密文asn.1编码格式转C1|C3|C2拼接格式
func Decrypt ¶
func Decrypt(priv *PrivateKey, data []byte, mode int) ([]byte, error)
DecryptAsn1 sm2解密,解析asn.1编码格式的密文内容
func DecryptAsn1 ¶
func DecryptAsn1(pub *PrivateKey, data []byte) ([]byte, error)
DecryptAsn1 sm2解密,解析asn.1编码格式的密文内容
func Encrypt ¶
Encrypt sm2非对称加密,支持C1C3C2(mode = 0)与C1C2C3(mode = 1)两种模式,默认使用C1C3C2模式。 不同的模式表示不同的密文结构,其中C1C2C3的意义: C1 : sm2椭圆曲线上的某个点,每次加密得到的点不一样 C2 : 密文 C3 : 明文加盐后的摘要
func EncryptAsn1 ¶
EncryptAsn1 sm2加密,返回asn.1编码格式的密文内容
func KeyExchangeA ¶
func KeyExchangeA(klen int, ida, idb []byte, priA *PrivateKey, pubB *PublicKey, rpri *PrivateKey, rpubB *PublicKey) (k, s1, s2 []byte, err error)
KeyExchangeA 协商第二部,用户A调用,返回共享密钥k
func KeyExchangeB ¶
func KeyExchangeB(klen int, ida, idb []byte, priB *PrivateKey, pubA *PublicKey, rpri *PrivateKey, rpubA *PublicKey) (k, s1, s2 []byte, err error)
KeyExchangeB 协商第二部,用户B调用, 返回共享密钥k
func Sm2Sign ¶
func Sm2Sign(priv *PrivateKey, signContentDigest, uid []byte, random io.Reader) (r, s *big.Int, err error)
Sm2Sign SM2签名
- priv : 签名私钥 *sm2.PrivateKey
- signContentDigest : 签名内容摘要(散列值)
- uid : 内部混合摘要计算用uid, 长度16的字节数组,可以传 nil
- random : 随机数获取用
func Sm2Verify ¶
Sm2Verify SM2验签
- pub : 验签公钥, *sm2.PublicKey
- signContentDigest : 签名内容摘要(散列值)
- uid : 内部混合摘要计算用uid, 长度16的字节数组,可以传 nil
- r, s : 签名
func VerifyASN1 ¶
VerifyASN1 使用公钥pub对hash和sig进行验签。
- pub 公钥
- hash 签名内容摘要(散列值)
- sig 签名DER字节数组(对(r,s)做了asn1编码,因此会先做asn1解码)
func WNafReversed ¶
Types ¶
type PrivateKey ¶
PrivateKey SM2私钥结构体
func GenerateKey ¶
func GenerateKey(random io.Reader) (*PrivateKey, error)
GenerateKey 基于P256Sm2曲线生成sm2的公私钥
func (*PrivateKey) Decrypt ¶
func (priv *PrivateKey) Decrypt(_ io.Reader, msg []byte, _ crypto.DecrypterOpts) (plaintext []byte, err error)
Decrypt crypto.Decrypter
func (*PrivateKey) DecryptAsn1 ¶
func (priv *PrivateKey) DecryptAsn1(data []byte) ([]byte, error)
DecryptAsn1 sm2解密,C1C3C2,asn1解码
func (*PrivateKey) Equal ¶
func (priv *PrivateKey) Equal(x crypto.PrivateKey) bool
func (*PrivateKey) Public ¶
func (priv *PrivateKey) Public() crypto.PublicKey
Public The SM2's private key contains the public key
func (*PrivateKey) Sign ¶
func (priv *PrivateKey) Sign(random io.Reader, signContentDigest []byte, signer crypto.SignerOpts) ([]byte, error)
Sign 使用priv私钥对签名内容摘要做SM2签名,参数signer目前没有使用,但仍要求传入外部对明文消息做摘要的散列算法。 使用priv私钥对签名内容摘要做SM2签名,参数signer目前没有使用,但仍要求传入外部对明文消息做摘要的散列算法。 返回的签名为DER字节数组,对(r,s)做了asn1编码。
- random : 随机数获取用, 如 rand.Reader
- signContentDigest : 签名内容摘要(散列值)
- signer : 外部对签名内容进行摘要计算使用的散列函数
type PublicKey ¶
PublicKey SM2公钥结构体
func Decompress ¶
func (*PublicKey) EncryptAsn1 ¶
EncryptAsn1 sm2加密,C1C3C2,asn1编码