Documentation ¶
Index ¶
- Constants
- func Add(x, y *big.Int) *big.Int
- func And(x, y *big.Int) *big.Int
- func Decrypt(priv *PrivateKey, in []byte, cipherTextType Sm2CipherTextType) ([]byte, error)
- func DecryptString(ciphertext, priKey string, cipherTypeOptional ...Sm2CipherTextType) (string, error)
- func Encrypt(pub *PublicKey, in []byte, cipherTextType Sm2CipherTextType) ([]byte, error)
- func EncryptString(text, pubKey string, cipherTypeOptional ...Sm2CipherTextType) (string, error)
- func GenerateKey(rand io.Reader) (*PrivateKey, *PublicKey, error)
- func GenerateKeyWithSalt(salt []byte) (*PrivateKey, *PublicKey, error)
- func IsEcPointInfinity(x, y *big.Int) bool
- func Lsh(x *big.Int, n uint) *big.Int
- func MarshalCipher(in []byte, cipherTextType Sm2CipherTextType) ([]byte, error)
- func MarshalSign(r, s *big.Int) ([]byte, error)
- func Mod(x, y *big.Int) *big.Int
- func ModInverse(x, y *big.Int) *big.Int
- func Mul(x, y *big.Int) *big.Int
- func SetBit(x *big.Int, i int, b uint) *big.Int
- func Sign(priv *PrivateKey, userId []byte, in []byte) ([]byte, error)
- func SignToRS(priv *PrivateKey, userId []byte, in []byte) (r, s *big.Int, err error)
- func Sub(x, y *big.Int) *big.Int
- func UnmarshalCipher(in []byte, cipherTextType Sm2CipherTextType) (out []byte, err error)
- func UnmarshalSign(sign []byte) (r, s *big.Int, err error)
- func Verify(pub *PublicKey, userId []byte, src []byte, sign []byte) bool
- func VerifyByRS(pub *PublicKey, userId []byte, src []byte, r, s *big.Int) bool
- func ZForAffine(x, y *big.Int) *big.Int
- type P256V1Curve
- type PrivateKey
- type PublicKey
- type Sm2CipherTextType
Constants ¶
View Source
const ( BitSize = 256 KeyBytes = (BitSize + 7) / 8 UnCompress = 0x04 DigestLength = 32 )
Variables ¶
This section is empty.
Functions ¶
func Decrypt ¶
func Decrypt(priv *PrivateKey, in []byte, cipherTextType Sm2CipherTextType) ([]byte, error)
func DecryptString ¶
func DecryptString(ciphertext, priKey string, cipherTypeOptional ...Sm2CipherTextType) (string, error)
DecryptString 简单参数,解密字符串
func Encrypt ¶
func Encrypt(pub *PublicKey, in []byte, cipherTextType Sm2CipherTextType) ([]byte, error)
func EncryptString ¶
func EncryptString(text, pubKey string, cipherTypeOptional ...Sm2CipherTextType) (string, error)
EncryptString 简单参数,加密字符串
func GenerateKey ¶
func GenerateKey(rand io.Reader) (*PrivateKey, *PublicKey, error)
func GenerateKeyWithSalt ¶
func GenerateKeyWithSalt(salt []byte) (*PrivateKey, *PublicKey, error)
func IsEcPointInfinity ¶
func MarshalCipher ¶
func MarshalCipher(in []byte, cipherTextType Sm2CipherTextType) ([]byte, error)
func UnmarshalCipher ¶
func UnmarshalCipher(in []byte, cipherTextType Sm2CipherTextType) (out []byte, err error)
Types ¶
type P256V1Curve ¶
type P256V1Curve struct { *elliptic.CurveParams A *big.Int }
func GetSm2P256V1 ¶
func GetSm2P256V1() P256V1Curve
type PrivateKey ¶
type PrivateKey struct { D *big.Int Curve P256V1Curve }
func RawBytesToPrivateKey ¶
func RawBytesToPrivateKey(bytes []byte) (*PrivateKey, error)
func (*PrivateKey) GetRawBytes ¶
func (pri *PrivateKey) GetRawBytes() []byte
type PublicKey ¶
type PublicKey struct {
X, Y *big.Int
Curve P256V1Curve
}
func CalculatePubKey ¶
func CalculatePubKey(priv *PrivateKey) *PublicKey
func RawBytesToPublicKey ¶
func (*PublicKey) GetRawBytes ¶
func (*PublicKey) GetUnCompressBytes ¶
type Sm2CipherTextType ¶
type Sm2CipherTextType int32
const ( // 旧标准的密文顺序 C1C2C3 Sm2CipherTextType = 1 // [GM/T 0009-2012]标准规定的顺序 C1C3C2 Sm2CipherTextType = 2 )
Click to show internal directories.
Click to hide internal directories.