Documentation ¶
Index ¶
- func BytesCombine(pBytes ...[]byte) []byte
- func CalculateSM2Hash(pub *PublicKey, msg, uid []byte) ([]byte, error)
- func CalculateZA(pub *PublicKey, uid []byte) ([]byte, error)
- func Compress(pub *PublicKey) []byte
- func Decrypt(priv *PrivateKey, data []byte, mode Mode) ([]byte, error)
- func DecryptASN1(priv *PrivateKey, data []byte, mode Mode) ([]byte, error)
- func Encrypt(random io.Reader, pub *PublicKey, data []byte, mode Mode) ([]byte, error)
- func EncryptASN1(rand io.Reader, pub *PublicKey, data []byte, mode Mode) ([]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 MarshalPrivateKey(key *PrivateKey) ([]byte, error)
- func MarshalPublicKey(key *PublicKey) ([]byte, error)
- func MarshalSM2PrivateKey(key *PrivateKey) ([]byte, error)
- func MarshalSignatureASN1(r, s *big.Int) ([]byte, error)
- func P256() elliptic.Curve
- func Sign(random io.Reader, priv *PrivateKey, hash []byte) (r, s *big.Int, err error)
- func SignWithSM2(random io.Reader, priv *PrivateKey, msg, uid []byte) (r, s *big.Int, err error)
- func ToPrivateKey(key *PrivateKey) []byte
- func ToPublicKey(key *PublicKey) []byte
- func UnmarshalSignatureASN1(sign []byte) (*big.Int, *big.Int, error)
- func Verify(pub *PublicKey, hash []byte, r, s *big.Int) bool
- func VerifyWithSM2(pub *PublicKey, msg, uid []byte, r, s *big.Int) bool
- type EncrypterOpts
- type Mode
- type PrivateKey
- func (priv *PrivateKey) Decrypt(_ io.Reader, msg []byte, opts crypto.DecrypterOpts) (plaintext []byte, err error)
- func (priv *PrivateKey) DecryptASN1(data []byte, opts crypto.DecrypterOpts) ([]byte, error)
- func (priv *PrivateKey) Equal(x crypto.PrivateKey) bool
- func (priv *PrivateKey) Public() crypto.PublicKey
- func (priv *PrivateKey) Sign(random io.Reader, msg []byte, opts crypto.SignerOpts) ([]byte, error)
- func (priv *PrivateKey) SignBytes(random io.Reader, msg []byte, opts crypto.SignerOpts) ([]byte, error)
- type PublicKey
- func (pub *PublicKey) Encrypt(random io.Reader, data []byte, opts crypto.DecrypterOpts) ([]byte, error)
- func (pub *PublicKey) EncryptASN1(random io.Reader, data []byte, opts crypto.DecrypterOpts) ([]byte, error)
- func (pub *PublicKey) Equal(x crypto.PublicKey) bool
- func (pub *PublicKey) Verify(msg []byte, sign []byte, opts crypto.SignerOpts) bool
- func (pub *PublicKey) VerifyBytes(msg []byte, sign []byte, opts crypto.SignerOpts) bool
- type SignerOpts
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BytesCombine ¶
func CalculateSM2Hash ¶ added in v1.0.2047
func CalculateZA ¶ added in v1.0.2047
CalculateZA ZA = H256(ENTLA || IDA || a || b || xG || yG || xA || yA)
func Decrypt ¶
func Decrypt(priv *PrivateKey, data []byte, mode Mode) ([]byte, error)
sm2 解密,解析字节拼接格式的密文内容 Decrypt bytes marshal data
func DecryptASN1 ¶ added in v1.0.2042
func DecryptASN1(priv *PrivateKey, data []byte, mode Mode) ([]byte, error)
sm2 解密,解析 asn.1 编码格式的密文内容 Decrypt asn.1 marshal data
func EncryptASN1 ¶ added in v1.0.2042
sm2 加密,返回 asn.1 编码格式的密文内容 Encrypted and return asn.1 data
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 MarshalPrivateKey ¶
func MarshalPrivateKey(key *PrivateKey) ([]byte, error)
func MarshalPublicKey ¶
func MarshalSM2PrivateKey ¶
func MarshalSM2PrivateKey(key *PrivateKey) ([]byte, error)
MarshalSM2PrivateKey converts an SM2 private key to SEC 1, ASN.1 DER form.
This kind of key is commonly encoded in PEM blocks of type "SM2 PRIVATE KEY". For a more flexible key format which is not SM2 specific, use MarshalPKCS8PrivateKey.
func MarshalSignatureASN1 ¶ added in v1.0.2047
func SignWithSM2 ¶
func UnmarshalSignatureASN1 ¶ added in v1.0.2047
Types ¶
type EncrypterOpts ¶
type EncrypterOpts struct {
Mode Mode
}
type PrivateKey ¶
func GenerateKey ¶
func GenerateKey(random io.Reader) (*PrivateKey, error)
生成私钥证书 generate PrivateKey
func NewPrivateKey ¶
func NewPrivateKey(d []byte) (*PrivateKey, error)
根据私钥明文初始化私钥 New a PrivateKey from privatekey data
func ParsePrivateKey ¶
func ParsePrivateKey(der []byte) (*PrivateKey, error)
func ParseSM2PrivateKey ¶
func ParseSM2PrivateKey(der []byte) (*PrivateKey, error)
ParseSM2PrivateKey parses an SM2 private key in SEC 1, ASN.1 DER form.
This kind of key is commonly encoded in PEM blocks of type "SM2 PRIVATE KEY".
func (*PrivateKey) Decrypt ¶
func (priv *PrivateKey) Decrypt(_ io.Reader, msg []byte, opts crypto.DecrypterOpts) (plaintext []byte, err error)
crypto.Decrypter
func (*PrivateKey) DecryptASN1 ¶ added in v1.0.2042
func (priv *PrivateKey) DecryptASN1(data []byte, opts crypto.DecrypterOpts) ([]byte, error)
func (*PrivateKey) Equal ¶
func (priv *PrivateKey) Equal(x crypto.PrivateKey) bool
Equal reports whether priv and x have the same value.
func (*PrivateKey) Public ¶
func (priv *PrivateKey) Public() crypto.PublicKey
The SM2's private key contains the public key
func (*PrivateKey) Sign ¶
func (priv *PrivateKey) Sign(random io.Reader, msg []byte, opts crypto.SignerOpts) ([]byte, error)
签名返回 asn.1 编码数据 sign data and return asn.1 marshal data
func (*PrivateKey) SignBytes ¶
func (priv *PrivateKey) SignBytes(random io.Reader, msg []byte, opts crypto.SignerOpts) ([]byte, error)
签名返回 Bytes 编码数据 sign data and return Bytes marshal data
type PublicKey ¶
func NewPublicKey ¶
根据公钥明文初始化公钥 New a PublicKey from publicKey data
func ParsePublicKey ¶
func (*PublicKey) EncryptASN1 ¶ added in v1.0.2042
func (*PublicKey) VerifyBytes ¶
验证 asn.1 编码的数据 ans1(r, s) Verify Bytes marshal data
type SignerOpts ¶
type SignerOpts struct {
Uid []byte
}
func (SignerOpts) HashFunc ¶
func (opt SignerOpts) HashFunc() crypto.Hash