sm2

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decryt added in v1.0.2

func Decryt(priv *PrivateKey, data []byte) ([]byte, error)

func Encryt added in v1.0.2

func Encryt(rand io.Reader, pub *PublicKey, msg []byte) ([]byte, error)

func MarshalSign

func MarshalSign(r, s *big.Int) ([]byte, error)

func Sign

func Sign(rand io.Reader, priv *PrivateKey, in, uid []byte) ([]byte, error)

原文裸签,返回DER编码的签名

func SignDigest added in v1.0.1

func SignDigest(rand io.Reader, priv *PrivateKey, digest []byte) ([]byte, error)

摘要签名,返回DER编码的签名

func SignDigestRS added in v1.0.1

func SignDigestRS(rand io.Reader, priv *PrivateKey, digest []byte) (r, s *big.Int, err error)

摘要签名,返回R||S

func SignRS

func SignRS(rand io.Reader, priv *PrivateKey, in, userId []byte) (r, s *big.Int, err error)

原文裸签,返回R||S

func UnmarshalSign

func UnmarshalSign(sig []byte) (r, s *big.Int, err error)

func Verify

func Verify(pub *PublicKey, in, uid, signature []byte) bool

签名验证(原文)

func VerifyDigest added in v1.0.1

func VerifyDigest(pub *PublicKey, in, signature []byte) bool

func VerifyDigestRS added in v1.0.1

func VerifyDigestRS(pub *PublicKey, digest []byte, r, s *big.Int) bool

func VerifyRS

func VerifyRS(pub *PublicKey, in []byte, uid []byte, r, s *big.Int) bool

Types

type P256V1Curve

type P256V1Curve struct {
	*elliptic.CurveParams
	A *big.Int
}

自定义SM2的椭圆曲线

func SM2P256V1 added in v1.0.2

func SM2P256V1() P256V1Curve

func (P256V1Curve) Params

func (curve P256V1Curve) Params() *elliptic.CurveParams

type PrivateKey

type PrivateKey struct {
	PublicKey
	D *big.Int
}

SM2 private key

func GenerateKey

func GenerateKey(random io.Reader) (*PrivateKey, error)

生成SM2密钥对

func (*PrivateKey) Equal

func (priv *PrivateKey) Equal(x crypto.PrivateKey) bool

implement crypto.PrivateKey

func (*PrivateKey) Public

func (priv *PrivateKey) Public() crypto.PublicKey

func (*PrivateKey) Sign

func (priv *PrivateKey) Sign(rand io.Reader, in, uid []byte) ([]byte, error)

原文裸签,返回DER编码的签名

func (*PrivateKey) SignDigest added in v1.0.1

func (priv *PrivateKey) SignDigest(rand io.Reader, digest []byte) ([]byte, error)

摘要签名,返回DER编码的签名

func (*PrivateKey) SignDigestRS added in v1.0.1

func (priv *PrivateKey) SignDigestRS(rand io.Reader, digest []byte) (r, s *big.Int, err error)

摘要签名,返回R||S

func (*PrivateKey) SignRS

func (priv *PrivateKey) SignRS(rand io.Reader, in []byte, uid []byte) (r, s *big.Int, err error)

原文裸签,返回R||S

type PublicKey

type PublicKey struct {
	elliptic.Curve
	X, Y *big.Int
}

SM2 public key

func (*PublicKey) Equal

func (pub *PublicKey) Equal(x crypto.PublicKey) bool

implement crypto.PublicKey

func (*PublicKey) SM3Digest added in v1.0.1

func (pub *PublicKey) SM3Digest(msg []byte, uid []byte) ([]byte, error)

SM2签名摘要算法实现,需要公钥与userid参与计算

func (*PublicKey) Verify

func (pub *PublicKey) Verify(in, uid, signature []byte) bool

func (*PublicKey) VerifyDigest added in v1.0.1

func (pub *PublicKey) VerifyDigest(in, signature []byte) bool

func (*PublicKey) VerifyDigestRS added in v1.0.1

func (pub *PublicKey) VerifyDigestRS(in []byte, r, s *big.Int) bool

func (*PublicKey) VerifyRS

func (pub *PublicKey) VerifyRS(in, uid []byte, r, s *big.Int) bool

Jump to

Keyboard shortcuts

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