Documentation ¶
Index ¶
- func ASN1Marshal(data []byte) ([]byte, error)
- func ASN1MarshalC1C2C3(data []byte) ([]byte, error)
- func ASN1Unmarshal(b []byte) ([]byte, error)
- func ASN1UnmarshalC1C2C3(b []byte) ([]byte, error)
- func BytesCombine(pBytes ...[]byte) []byte
- func Compress(a *PublicKey) []byte
- func Decrypt(priv *PrivateKey, data []byte, mode Mode) ([]byte, error)
- func DecryptAsn1(pub *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 P256Sm2() elliptic.Curve
- func Sign(random io.Reader, priv *PrivateKey, hash []byte) (r, s *big.Int, err error)
- func SignDataToSignDigit(sign []byte) (*big.Int, *big.Int, error)
- func SignDigitToSignData(r, s *big.Int) ([]byte, 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 Verify(pub *PublicKey, hash []byte, r, s *big.Int) bool
- func VerifyWithSM2(pub *PublicKey, msg, uid []byte, r, s *big.Int) bool
- func WNafReversed(wnaf []int8) []int8
- func ZA(pub *PublicKey, uid []byte) ([]byte, error)
- 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 ASN1Marshal ¶
sm2 密文转 asn.1 编码格式 sm2 密文结构: x + y + hash + CipherText
func ASN1MarshalC1C2C3 ¶
sm2 密文转 asn.1 编码格式 sm2 密文结构: x + y + hash + CipherText
func ASN1UnmarshalC1C2C3 ¶
sm2 密文 asn.1 编码格式转 C1|C2|C3 拼接格式
func BytesCombine ¶
func DecryptAsn1 ¶
func DecryptAsn1(pub *PrivateKey, data []byte, mode Mode) ([]byte, error)
sm2解密,解析asn.1编码格式的密文内容
func 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 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 SignWithSM2 ¶
func WNafReversed ¶
Types ¶
type EncrypterOpts ¶
type EncrypterOpts struct {
Mode Mode
}
type PrivateKey ¶
func GenerateKey ¶
func GenerateKey(random io.Reader) (*PrivateKey, error)
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 ¶
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)
sign format = 30 + len(z) + 02 + len(r) + r + 02 + len(s) + s, z being what follows its size, ie 02+len(r)+r+02+len(s)+s
func (*PrivateKey) SignBytes ¶
func (priv *PrivateKey) SignBytes(random io.Reader, msg []byte, opts crypto.SignerOpts) ([]byte, error)
type PublicKey ¶
func Decompress ¶
func ParsePublicKey ¶
func (*PublicKey) EncryptAsn1 ¶
func (*PublicKey) VerifyBytes ¶
type SignerOpts ¶
type SignerOpts struct {
Uid []byte
}
func (SignerOpts) HashFunc ¶
func (opt SignerOpts) HashFunc() crypto.Hash