Documentation ¶
Index ¶
- func Decrypt(priv *SM2PrivateKey, data []byte) ([]byte, error)
- func Encrypt(pub *SM2PublicKey, data []byte, ivReader io.Reader) ([]byte, error)
- func GenerateSM2KeyForDH(idA, idB, randA []byte, ...) (*big.Int, *big.Int, []byte, error)
- func GetSM3Hasher() hash.Hash
- func GetSm2Curve() elliptic.Curve
- func GetSm4Cipher(key []byte) (cipher.Block, error)
- func HashBeforeSM2(pub *SM2PublicKey, msg []byte) []byte
- func NewSM3IDHasher() hash.Hash
- func Sm4DecryptCBC(key, src []byte) ([]byte, error)
- func Sm4EncryptCBC(key, originMsg []byte, randReader io.Reader) ([]byte, error)
- type Hasher
- func (h *Hasher) BatchHash(msg [][]byte) (hash []byte, err error)
- func (h *Hasher) BlockSize() int
- func (h *Hasher) Hash(msg []byte) (hash []byte, err error)
- func (h *Hasher) Reset()
- func (h *Hasher) Size() int
- func (h *Hasher) Sum(b []byte) []byte
- func (h *Hasher) Write(p []byte) (n int, err error)
- type IDHasher
- func (h *IDHasher) BatchHash(msg [][]byte) (hash []byte, err error)
- func (h *IDHasher) BlockSize() int
- func (h *IDHasher) Hash(msg []byte) (hash []byte, err error)
- func (h *IDHasher) Reset()
- func (h *IDHasher) Size() int
- func (h *IDHasher) Sum(b []byte) []byte
- func (h *IDHasher) Write(p []byte) (n int, err error)
- type SM2
- type SM2PrivateKey
- func (key *SM2PrivateKey) Bytes() ([]byte, error)
- func (key *SM2PrivateKey) CalculatePublicKey() *SM2PrivateKey
- func (key *SM2PrivateKey) FromBytes(k []byte, opt int) error
- func (key *SM2PrivateKey) Public() std.PublicKey
- func (key *SM2PrivateKey) SetPublicKey(k *SM2PublicKey) *SM2PrivateKey
- func (key *SM2PrivateKey) Sign(k, digest []byte, reader io.Reader) ([]byte, error)
- func (key *SM2PrivateKey) SignBatch(k, digest []byte, reader io.Reader) ([]byte, error)
- type SM2PublicKey
- type SM4
- type SM4Key
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Decrypt ¶
func Decrypt(priv *SM2PrivateKey, data []byte) ([]byte, error)
Decrypt sm2 ecc decrypt
func GenerateSM2KeyForDH ¶
func GenerateSM2KeyForDH(idA, idB, randA []byte, privateKey, publicAX, publicAY, publicBX, publicBY *big.Int, RB *SM2PublicKey, isInit bool) (*big.Int, *big.Int, []byte, error)
GenerateSM2KeyForDH generate a key using sm2 for dh idA is the ID of self, idB is the ID of another part, isInit indicates whether it is the initiator or not
func GetSm4Cipher ¶
GetSm4Cipher get cipher.Block
func HashBeforeSM2 ¶
func HashBeforeSM2(pub *SM2PublicKey, msg []byte) []byte
HashBeforeSM2 If hash is for using sm2, invoke this method.
func Sm4DecryptCBC ¶
Sm4DecryptCBC decrypt with sm4, use CBC mode with iv
Types ¶
type Hasher ¶
type Hasher struct {
// contains filtered or unexported fields
}
Hasher thw return value of function NewHasher
type IDHasher ¶
type IDHasher struct {
// contains filtered or unexported fields
}
IDHasher thw return value of function NewHasher
type SM2 ¶
type SM2 struct { }
SM2 SM2 instance is a tool to sign and verify. You can sign and verify via SM2PrivateKey and SM2PublicKey, SM2 instance is just a package of SM2PrivateKey's Sign and SM2PublicKey's Verify. If you need revoke Sign or Verify at a sepcific Key many times, we recommend using SM2PrivateKey and SM2PublicKey, which avoid decode and alloc repeatedly. All in all, SM2 is convenient; SM2PrivateKey and SM2PublicKey are faster.
type SM2PrivateKey ¶
type SM2PrivateKey struct { K [sm2KeyLen]byte PublicKey SM2PublicKey }
SM2PrivateKey SM2 private key. never new(SM2PrivateKey), use NewSM2PrivateKey()
func GenerateSM2Key ¶
func GenerateSM2Key() (*SM2PrivateKey, error)
GenerateSM2Key generate a pair of key,input is algorithm type
func (*SM2PrivateKey) Bytes ¶
func (key *SM2PrivateKey) Bytes() ([]byte, error)
Bytes return key bytes. Inverse method of FromBytes(K []byte, opt AlgorithmOption)
func (*SM2PrivateKey) CalculatePublicKey ¶
func (key *SM2PrivateKey) CalculatePublicKey() *SM2PrivateKey
CalculatePublicKey Calculate the public key contained in the private key when get a SM2PrivateKey by FromBytes(...), the public key contained is empty, you should invoke SetPublicKey(...) or CalculatePublicKey(). If you have the Public Key,SetPublicKey(...) is better and faster, since CalculatePublicKey() while calculate public key once again.
func (*SM2PrivateKey) FromBytes ¶
func (key *SM2PrivateKey) FromBytes(k []byte, opt int) error
FromBytes parse a private Key from bytes, Inverse method of Bytes()
func (*SM2PrivateKey) Public ¶
func (key *SM2PrivateKey) Public() std.PublicKey
Public Get SM2PublicKey from a SM2PrivateKey, if SM2PublicKey is empty, this method will invoke CalculatePublicKey().
func (*SM2PrivateKey) SetPublicKey ¶
func (key *SM2PrivateKey) SetPublicKey(k *SM2PublicKey) *SM2PrivateKey
SetPublicKey Set the public key contained in the private key when get a SM2PrivateKey by FromBytes(...), the public key contained is empty, you should invoke SetPublicKey(...) or CalculatePublicKey(). If you have the Public Key,SetPublicKey(...) is better and faster, since CalculatePublicKey() while calculate public key once again.
type SM2PublicKey ¶
SM2PublicKey SM2 public key. never new(SM2PublicKey), use NewSM2PublicKey()
func (*SM2PublicKey) Bytes ¶
func (key *SM2PublicKey) Bytes() ([]byte, error)
Bytes return key bytes