Documentation ¶
Index ¶
- Constants
- Variables
- type HashFunc
- type Opts
- type PBKDF2Opts
- type SM2
- func FromBase64String(data string) SM2
- func FromBytes(data []byte) SM2
- func FromHexString(data string) SM2
- func FromPKCS1PrivateKey(key []byte) SM2
- func FromPKCS1PrivateKeyWithPassword(key []byte, password string) SM2
- func FromPKCS8PrivateKey(key []byte) SM2
- func FromPKCS8PrivateKeyWithPassword(key []byte, password string) SM2
- func FromPrivateKey(key []byte) SM2
- func FromPrivateKeyWithPassword(key []byte, password string) SM2
- func FromPublicKey(key []byte) SM2
- func FromString(data string) SM2
- func GenerateKey() SM2
- func GenerateKeyWithSeed(reader io.Reader) SM2
- func New() SM2
- func NewSM2() SM2
- func (this SM2) AppendError(errs ...error) SM2
- func (this SM2) CheckKeyPair() bool
- func (this SM2) CreatePKCS1PrivateKey() SM2
- func (this SM2) CreatePKCS1PrivateKeyWithPassword(password string, opts ...string) SM2
- func (this SM2) CreatePKCS8PrivateKey() SM2
- func (this SM2) CreatePKCS8PrivateKeyWithPassword(password string, opts ...any) SM2
- func (this SM2) CreatePrivateKey() SM2
- func (this SM2) CreatePrivateKeyWithPassword(password string, opts ...any) SM2
- func (this SM2) CreatePublicKey() SM2
- func (this SM2) Decrypt() SM2
- func (this SM2) DecryptASN1() SM2
- func (this SM2) DecryptASN1ECB() SM2
- func (this SM2) DecryptECB() SM2
- func (this SM2) Encrypt() SM2
- func (this SM2) EncryptASN1() SM2
- func (this SM2) EncryptASN1ECB() SM2
- func (this SM2) EncryptECB() SM2
- func (this SM2) Error() error
- func (this SM2) FromBase64String(data string) SM2
- func (this SM2) FromBytes(data []byte) SM2
- func (this SM2) FromHexString(data string) SM2
- func (this SM2) FromPKCS1PrivateKey(key []byte) SM2
- func (this SM2) FromPKCS1PrivateKeyDer(der []byte) SM2
- func (this SM2) FromPKCS1PrivateKeyWithPassword(key []byte, password string) SM2
- func (this SM2) FromPKCS8PrivateKey(key []byte) SM2
- func (this SM2) FromPKCS8PrivateKeyDer(der []byte) SM2
- func (this SM2) FromPKCS8PrivateKeyWithPassword(key []byte, password string) SM2
- func (this SM2) FromPrivateKey(key []byte) SM2
- func (this SM2) FromPrivateKeyBytes(priBytes []byte) SM2
- func (this SM2) FromPrivateKeyString(keyString string) SM2
- func (this SM2) FromPrivateKeyWithPassword(key []byte, password string) SM2
- func (this SM2) FromPublicKey(key []byte) SM2
- func (this SM2) FromPublicKeyBytes(pubBytes []byte) SM2
- func (this SM2) FromPublicKeyCompressString(key string) SM2
- func (this SM2) FromPublicKeyDer(der []byte) SM2
- func (this SM2) FromPublicKeyString(key string) SM2
- func (this SM2) FromPublicKeyUncompressString(keyString string) SM2
- func (this SM2) FromPublicKeyXYBytes(XBytes, YBytes []byte) SM2
- func (this SM2) FromPublicKeyXYString(xString, yString string) SM2
- func (this SM2) FromString(data string) SM2
- func (this SM2) GenerateKey() SM2
- func (this SM2) GenerateKeyWithSeed(reader io.Reader) SM2
- func (this SM2) GetData() []byte
- func (this SM2) GetErrors() []error
- func (this SM2) GetKeyData() []byte
- func (this SM2) GetMode() sm2.Mode
- func (this SM2) GetParsedData() []byte
- func (this SM2) GetPrivateKey() *sm2.PrivateKey
- func (this SM2) GetPrivateKeyCurve() elliptic.Curve
- func (this SM2) GetPrivateKeyDString() string
- func (this SM2) GetPrivateKeyString() string
- func (this SM2) GetPublicKey() *sm2.PublicKey
- func (this SM2) GetPublicKeyCompressString() string
- func (this SM2) GetPublicKeyCurve() elliptic.Curve
- func (this SM2) GetPublicKeyUncompressString() string
- func (this SM2) GetPublicKeyXString() string
- func (this SM2) GetPublicKeyXYString() string
- func (this SM2) GetPublicKeyYString() string
- func (this SM2) GetUID() []byte
- func (this SM2) GetVerify() bool
- func (this SM2) MakeKeyDer() SM2
- func (this SM2) MakePublicKey() SM2
- func (this SM2) OnError(fn SM2ErrorFunc) SM2
- func (this SM2) ParsePKCS1PrivateKeyFromPEM(key []byte) (*sm2.PrivateKey, error)
- func (this SM2) ParsePKCS1PrivateKeyFromPEMWithPassword(key []byte, password string) (*sm2.PrivateKey, error)
- func (this SM2) ParsePKCS8PrivateKeyFromPEM(key []byte) (*sm2.PrivateKey, error)
- func (this SM2) ParsePKCS8PrivateKeyFromPEMWithPassword(key []byte, password string) (*sm2.PrivateKey, error)
- func (this SM2) ParsePrivateKeyFromPEM(key []byte) (*sm2.PrivateKey, error)
- func (this SM2) ParsePrivateKeyFromPEMWithPassword(key []byte, password string) (*sm2.PrivateKey, error)
- func (this SM2) ParsePublicKeyFromPEM(key []byte) (*sm2.PublicKey, error)
- func (this SM2) SetMode(data string) SM2
- func (this SM2) SetSignHash(data string) SM2
- func (this SM2) SetUID(data string) SM2
- func (this SM2) Sign() SM2
- func (this SM2) SignASN1() SM2
- func (this SM2) SignBytes() SM2
- func (this SM2) ToBase64String() string
- func (this SM2) ToBytes() []byte
- func (this SM2) ToHexString() string
- func (this SM2) ToKeyBytes() []byte
- func (this SM2) ToKeyString() string
- func (this SM2) ToString() string
- func (this SM2) ToVerify() bool
- func (this SM2) ToVerifyInt() int
- func (this SM2) Verify(data []byte) SM2
- func (this SM2) VerifyASN1(data []byte) SM2
- func (this SM2) VerifyBytes(data []byte) SM2
- func (this SM2) WithData(data []byte) SM2
- func (this SM2) WithErrors(errs []error) SM2
- func (this SM2) WithMode(data sm2.Mode) SM2
- func (this SM2) WithParsedData(data []byte) SM2
- func (this SM2) WithPrivateKey(data *sm2.PrivateKey) SM2
- func (this SM2) WithPublicKey(data *sm2.PublicKey) SM2
- func (this SM2) WithSignHash(data HashFunc) SM2
- func (this SM2) WithUID(data []byte) SM2
- func (this SM2) WithVerify(data bool) SM2
- type SM2ErrorFunc
- type ScryptOpts
Constants ¶
const ( // 类型 C1C3C2 = sm2.C1C3C2 C1C2C3 = sm2.C1C2C3 )
Variables ¶
var ( // 获取 Cipher 类型 GetCipherFromName = pkcs8.GetCipherFromName // 获取 hash 类型 GetHashFromName = pkcs8.GetHashFromName )
var ( ErrKeyMustBePEMEncoded = errors.New("invalid key: Key must be a PEM encoded PKCS1 or PKCS8 key") ErrNotECPrivateKey = errors.New("key is not a valid SM2 private key") )
Functions ¶
This section is empty.
Types ¶
type SM2 ¶
type SM2 struct { // 错误 Errors []error // contains filtered or unexported fields }
*
- 国密 SM2 加密 *
- @create 2022-4-16
- @author deatil
func FromPKCS1PrivateKeyWithPassword ¶ added in v1.0.2027
PKCS1 私钥带密码
func FromPKCS8PrivateKeyWithPassword ¶ added in v1.0.2027
PKCS8 私钥带密码
func FromPrivateKeyWithPassword ¶ added in v1.0.1018
私钥带密码
func GenerateKeyWithSeed ¶ added in v1.0.2026
使用自定义数据生成密钥对
func (SM2) CreatePKCS1PrivateKey ¶ added in v1.0.2027
生成私钥 pem 数据
func (SM2) CreatePKCS1PrivateKeyWithPassword ¶ added in v1.0.2027
生成私钥带密码 pem 数据
func (SM2) CreatePKCS8PrivateKey ¶ added in v1.0.2027
生成私钥 pem 数据
func (SM2) CreatePKCS8PrivateKeyWithPassword ¶ added in v1.0.1028
生成 PKCS8 私钥带密码 pem 数据 CreatePKCS8PrivateKeyWithPassword("123", "AES256CBC", "SHA256")
func (SM2) CreatePrivateKey ¶
生成私钥 pem 数据,默认使用 PKCS8 编码 使用: obj := New().GenerateKey() priKey := obj.CreatePrivateKey().ToKeyString()
func (SM2) CreatePrivateKeyWithPassword ¶
生成私钥带密码 pem 数据
func (SM2) DecryptASN1 ¶ added in v1.0.2042
私钥解密,解析 asn.1 编码格式的密文内容
func (SM2) DecryptASN1ECB ¶ added in v1.0.2069
私钥解密,返回 asn.1 编码格式的密文内容, ECB 模式
func (SM2) EncryptASN1 ¶ added in v1.0.2042
公钥加密,返回 asn.1 编码格式的密文内容
func (SM2) EncryptASN1ECB ¶ added in v1.0.2069
公钥加密,返回 asn.1 编码格式的密文内容, ECB 模式
func (SM2) FromPKCS1PrivateKey ¶ added in v1.0.2027
PKCS1 私钥
func (SM2) FromPKCS1PrivateKeyDer ¶ added in v1.0.2027
PKCS1 编码 DER 私钥
func (SM2) FromPKCS1PrivateKeyWithPassword ¶ added in v1.0.2027
PKCS1 私钥带密码
func (SM2) FromPKCS8PrivateKey ¶ added in v1.0.2027
PKCS8 私钥
func (SM2) FromPKCS8PrivateKeyDer ¶ added in v1.0.2027
PKCS8 编码 DER 私钥
func (SM2) FromPKCS8PrivateKeyWithPassword ¶ added in v1.0.2027
PKCS8 私钥带密码
func (SM2) FromPrivateKeyBytes ¶
私钥明文, hex 或者 base64 解码后
func (SM2) FromPrivateKeyString ¶
私钥明文 private-key: 07e4********;
func (SM2) FromPrivateKeyWithPassword ¶
私钥带密码
func (SM2) FromPublicKeyBytes ¶ added in v1.0.2027
公钥明文, hex 或者 base64 解码后
func (SM2) FromPublicKeyCompressString ¶ added in v1.0.2027
公钥明文压缩 public-key: 027c******** || 036c******** 0333B01B61D94A775DA72A0BFF9AB324DE672EA0977584D23AF34F8150223305B0 023613B13F252F6FB2374A85D93C7FFE9CCAD1231BE866F5FE69255312CE85B9FF
func (SM2) FromPublicKeyDer ¶ added in v1.0.2015
DER 公钥
func (SM2) FromPublicKeyUncompressString ¶ added in v1.0.2027
公钥明文未压缩 (hexStringX + hexStringY) public-key: 047c********.
func (SM2) FromPublicKeyXYBytes ¶
公钥 x,y 字节对
func (SM2) FromPublicKeyXYString ¶ added in v1.0.1018
公钥 x,y 16进制字符对 [xString: xHexString, yString: yHexString]
func (SM2) GenerateKeyWithSeed ¶ added in v1.0.2026
使用自定义数据生成密钥对
func (SM2) GetPrivateKeyCurve ¶
get PrivateKey Curve
func (SM2) GetPrivateKeyDString ¶ added in v1.0.2071
get PrivateKey D hex string
func (SM2) GetPrivateKeyString ¶ added in v1.0.2027
get PrivateKey data hex string
func (SM2) GetPublicKeyCompressString ¶ added in v1.0.2027
get PublicKey Compress Hex string
func (SM2) GetPublicKeyCurve ¶
get PublicKey Curve
func (SM2) GetPublicKeyUncompressString ¶ added in v1.0.2027
get PublicKey Uncompress Hex string
func (SM2) GetPublicKeyXString ¶ added in v1.0.2071
get PublicKey X hex string
func (SM2) GetPublicKeyXYString ¶ added in v1.0.2071
get PublicKey X and Y Hex string
func (SM2) GetPublicKeyYString ¶ added in v1.0.2071
get PublicKey Y hex string
func (SM2) ParsePKCS1PrivateKeyFromPEM ¶ added in v1.0.2027
func (this SM2) ParsePKCS1PrivateKeyFromPEM(key []byte) (*sm2.PrivateKey, error)
解析 PKCS1 私钥
func (SM2) ParsePKCS1PrivateKeyFromPEMWithPassword ¶ added in v1.0.2027
func (this SM2) ParsePKCS1PrivateKeyFromPEMWithPassword(key []byte, password string) (*sm2.PrivateKey, error)
解析 PKCS1 私钥带密码
func (SM2) ParsePKCS8PrivateKeyFromPEM ¶ added in v1.0.2027
func (this SM2) ParsePKCS8PrivateKeyFromPEM(key []byte) (*sm2.PrivateKey, error)
解析 PKCS8 私钥
func (SM2) ParsePKCS8PrivateKeyFromPEMWithPassword ¶ added in v1.0.1028
func (this SM2) ParsePKCS8PrivateKeyFromPEMWithPassword(key []byte, password string) (*sm2.PrivateKey, error)
解析 PKCS8 带密码的私钥
func (SM2) ParsePrivateKeyFromPEM ¶
func (this SM2) ParsePrivateKeyFromPEM(key []byte) (*sm2.PrivateKey, error)
解析私钥,默认为 PKCS8
func (SM2) ParsePrivateKeyFromPEMWithPassword ¶
func (this SM2) ParsePrivateKeyFromPEMWithPassword(key []byte, password string) (*sm2.PrivateKey, error)
解析私钥带密码,默认为 PKCS8
func (SM2) ParsePublicKeyFromPEM ¶
解析公钥
func (SM2) SetSignHash ¶ added in v1.0.2048
设置 hash 类型 可用参数可查看 Hash 结构体数据
func (SM2) VerifyASN1 ¶ added in v1.0.2039
公钥验证 ASN1 使用原始数据[data]对比签名后数据
func (SM2) VerifyBytes ¶ added in v1.0.2039
公钥验证 Bytes 兼容[招行] 使用原始数据[data]对比签名后数据
func (SM2) WithParsedData ¶ added in v1.0.2049
设置 parsedData
func (SM2) WithSignHash ¶ added in v1.0.2048
设置 hash 类型