github.com/chain5j/chain5j-pkg@v1.0.7/crypto/crypto_ecdsa.go (about)

     1  // Package crypto
     2  //
     3  // @author: xwc1125
     4  package crypto
     5  
     6  import (
     7  	"crypto"
     8  	"crypto/ecdsa"
     9  	"crypto/elliptic"
    10  	"hash"
    11  )
    12  
    13  type ECDSA interface {
    14  	GenerateKey(curve elliptic.Curve) (*ecdsa.PrivateKey, error)
    15  
    16  	HashType(curveName string) crypto.Hash
    17  	HashFunc(cryptoName string) func() hash.Hash
    18  	HashMsg(cryptoName string, data []byte) ([]byte, error)
    19  
    20  	ToECDSA(prv crypto.PrivateKey) *ecdsa.PrivateKey
    21  	FromECDSA(prv *ecdsa.PrivateKey) crypto.PrivateKey
    22  	ToECDSAPubKey(pub crypto.PublicKey) *ecdsa.PublicKey
    23  	FromECDSAPubKey(pub *ecdsa.PublicKey) crypto.PublicKey
    24  
    25  	MarshalPrivateKey(key *ecdsa.PrivateKey) ([]byte, error)
    26  	UnmarshalPrivateKey(curve elliptic.Curve, keyBytes []byte) (*ecdsa.PrivateKey, error)
    27  	MarshalPublicKey(pub *ecdsa.PublicKey) ([]byte, error)
    28  	UnmarshalPublicKey(curve elliptic.Curve, data []byte) (*ecdsa.PublicKey, error)
    29  
    30  	MarshalPrivateKeyX509(key *ecdsa.PrivateKey) ([]byte, error)
    31  	UnmarshalPrivateKeyX509(curve elliptic.Curve, keyBytes []byte) (*ecdsa.PrivateKey, error)
    32  	MarshalPublicKeyX509(pub *ecdsa.PublicKey) ([]byte, error)
    33  	UnmarshalPublicKeyX509(curve elliptic.Curve, data []byte) (*ecdsa.PublicKey, error)
    34  
    35  	Sign(prv *ecdsa.PrivateKey, hash []byte) (sig []byte, err error)
    36  	Verify(pub *ecdsa.PublicKey, hash []byte, signature []byte) bool
    37  }