sm2

package
v1.0.5006 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: Apache-2.0 Imports: 17 Imported by: 3

Documentation

Index

Constants

View Source
const (
	// 类型
	C1C3C2 = sm2.C1C3C2
	C1C2C3 = sm2.C1C2C3
)

Variables

View Source
var (
	// 获取 Cipher 类型
	GetCipherFromName = pkcs8.GetCipherFromName
	// 获取 hash 类型
	GetHashFromName = pkcs8.GetHashFromName
)
View Source
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 EncodingType added in v1.0.3009

type EncodingType uint

数据编码方式 marshal data type

const (
	EncodingASN1 EncodingType = 1 + iota
	EncodingBytes
)

type HashFunc added in v1.0.2048

type HashFunc = func() hash.Hash

HashFunc

type Opts added in v1.0.1028

type Opts = pkcs8.Opts

配置

type PBKDF2Opts added in v1.0.1028

type PBKDF2Opts = pkcs8.PBKDF2Opts

PBKDF2 配置

type SM2

type SM2 struct {

	// 错误
	Errors []error
	// contains filtered or unexported fields
}

*

  • 国密 SM2 加密 *
  • @create 2022-4-16
  • @author deatil

func FromBase64String added in v1.0.1018

func FromBase64String(data string) SM2

Base64数据

func FromBytes added in v1.0.1018

func FromBytes(data []byte) SM2

字节

func FromHexString added in v1.0.1018

func FromHexString(data string) SM2

16进制数据

func FromPKCS1PrivateKey added in v1.0.2027

func FromPKCS1PrivateKey(key []byte) SM2

PKCS1 私钥

func FromPKCS1PrivateKeyWithPassword added in v1.0.2027

func FromPKCS1PrivateKeyWithPassword(key []byte, password string) SM2

PKCS1 私钥带密码

func FromPKCS8PrivateKey added in v1.0.2027

func FromPKCS8PrivateKey(key []byte) SM2

PKCS8 私钥

func FromPKCS8PrivateKeyWithPassword added in v1.0.2027

func FromPKCS8PrivateKeyWithPassword(key []byte, password string) SM2

PKCS8 私钥带密码

func FromPrivateKey added in v1.0.1018

func FromPrivateKey(key []byte) SM2

私钥

func FromPrivateKeyWithPassword added in v1.0.1018

func FromPrivateKeyWithPassword(key []byte, password string) SM2

私钥带密码

func FromPublicKey added in v1.0.1018

func FromPublicKey(key []byte) SM2

公钥,默认只有一种类型

func FromString added in v1.0.1018

func FromString(data string) SM2

字符

func GenerateKey added in v1.0.1018

func GenerateKey() SM2

生成密钥对

func GenerateKeyWithSeed added in v1.0.2026

func GenerateKeyWithSeed(reader io.Reader) SM2

使用自定义数据生成密钥对

func New added in v1.0.1018

func New() SM2

构造函数

func NewSM2

func NewSM2() SM2

构造函数

func (SM2) AppendError added in v1.0.1026

func (this SM2) AppendError(errs ...error) SM2

添加错误

func (SM2) CheckKeyPair added in v1.0.1043

func (this SM2) CheckKeyPair() bool

检测公钥私钥是否匹配

func (SM2) CreatePKCS1PrivateKey added in v1.0.2027

func (this SM2) CreatePKCS1PrivateKey() SM2

生成私钥 pem 数据

func (SM2) CreatePKCS1PrivateKeyWithPassword added in v1.0.2027

func (this SM2) CreatePKCS1PrivateKeyWithPassword(password string, opts ...string) SM2

生成私钥带密码 pem 数据

func (SM2) CreatePKCS8PrivateKey added in v1.0.2027

func (this SM2) CreatePKCS8PrivateKey() SM2

生成私钥 pem 数据

func (SM2) CreatePKCS8PrivateKeyWithPassword added in v1.0.1028

func (this SM2) CreatePKCS8PrivateKeyWithPassword(password string, opts ...any) SM2

生成 PKCS8 私钥带密码 pem 数据 CreatePKCS8PrivateKeyWithPassword("123", "AES256CBC", "SHA256")

func (SM2) CreatePrivateKey

func (this SM2) CreatePrivateKey() SM2

生成私钥 pem 数据,默认使用 PKCS8 编码 使用: obj := New().GenerateKey() priKey := obj.CreatePrivateKey().ToKeyString()

func (SM2) CreatePrivateKeyWithPassword

func (this SM2) CreatePrivateKeyWithPassword(password string, opts ...any) SM2

生成私钥带密码 pem 数据

func (SM2) CreatePublicKey

func (this SM2) CreatePublicKey() SM2

生成公钥 pem 数据

func (SM2) Decrypt

func (this SM2) Decrypt() SM2

私钥解密

func (SM2) DecryptASN1 added in v1.0.2042

func (this SM2) DecryptASN1() SM2

私钥解密,解析 asn.1 编码格式的密文内容

func (SM2) DecryptASN1ECB added in v1.0.2069

func (this SM2) DecryptASN1ECB() SM2

私钥解密,返回 asn.1 编码格式的密文内容, ECB 模式

func (SM2) DecryptBytes added in v1.0.3009

func (this SM2) DecryptBytes() SM2

私钥解密

func (SM2) DecryptBytesECB added in v1.0.3009

func (this SM2) DecryptBytesECB() SM2

私钥解密, ECB 模式

func (SM2) DecryptECB added in v1.0.2069

func (this SM2) DecryptECB() SM2

私钥解密

func (SM2) Encrypt

func (this SM2) Encrypt() SM2

公钥加密

func (SM2) EncryptASN1 added in v1.0.2042

func (this SM2) EncryptASN1() SM2

公钥加密,返回 asn.1 编码格式的密文内容

func (SM2) EncryptASN1ECB added in v1.0.2069

func (this SM2) EncryptASN1ECB() SM2

公钥加密,返回 asn.1 编码格式的密文内容, ECB 模式

func (SM2) EncryptBytes added in v1.0.3009

func (this SM2) EncryptBytes() SM2

公钥加密

func (SM2) EncryptBytesECB added in v1.0.3009

func (this SM2) EncryptBytesECB() SM2

公钥加密, ECB 模式

func (SM2) EncryptECB added in v1.0.2069

func (this SM2) EncryptECB() SM2

公钥加密

func (SM2) Error

func (this SM2) Error() error

获取错误

func (SM2) FromBase64String

func (this SM2) FromBase64String(data string) SM2

Base64数据

func (SM2) FromBytes

func (this SM2) FromBytes(data []byte) SM2

字节

func (SM2) FromHexString

func (this SM2) FromHexString(data string) SM2

16进制数据

func (SM2) FromPKCS1PrivateKey added in v1.0.2027

func (this SM2) FromPKCS1PrivateKey(key []byte) SM2

PKCS1 私钥

func (SM2) FromPKCS1PrivateKeyDer added in v1.0.2027

func (this SM2) FromPKCS1PrivateKeyDer(der []byte) SM2

PKCS1 编码 DER 私钥

func (SM2) FromPKCS1PrivateKeyWithPassword added in v1.0.2027

func (this SM2) FromPKCS1PrivateKeyWithPassword(key []byte, password string) SM2

PKCS1 私钥带密码

func (SM2) FromPKCS8PrivateKey added in v1.0.2027

func (this SM2) FromPKCS8PrivateKey(key []byte) SM2

PKCS8 私钥

func (SM2) FromPKCS8PrivateKeyDer added in v1.0.2027

func (this SM2) FromPKCS8PrivateKeyDer(der []byte) SM2

PKCS8 编码 DER 私钥

func (SM2) FromPKCS8PrivateKeyWithPassword added in v1.0.2027

func (this SM2) FromPKCS8PrivateKeyWithPassword(key []byte, password string) SM2

PKCS8 私钥带密码

func (SM2) FromPrivateKey

func (this SM2) FromPrivateKey(key []byte) SM2

私钥

func (SM2) FromPrivateKeyBytes

func (this SM2) FromPrivateKeyBytes(priBytes []byte) SM2

私钥明文, hex 或者 base64 解码后

func (SM2) FromPrivateKeyString

func (this SM2) FromPrivateKeyString(keyString string) SM2

私钥明文 private-key: 07e4********;

func (SM2) FromPrivateKeyWithPassword

func (this SM2) FromPrivateKeyWithPassword(key []byte, password string) SM2

私钥带密码

func (SM2) FromPublicKey

func (this SM2) FromPublicKey(key []byte) SM2

公钥,默认只有一种类型

func (SM2) FromPublicKeyBytes added in v1.0.2027

func (this SM2) FromPublicKeyBytes(pubBytes []byte) SM2

公钥明文, hex 或者 base64 解码后

func (SM2) FromPublicKeyCompressString added in v1.0.2027

func (this SM2) FromPublicKeyCompressString(key string) SM2

公钥明文压缩 public-key: 027c******** || 036c******** 0333B01B61D94A775DA72A0BFF9AB324DE672EA0977584D23AF34F8150223305B0 023613B13F252F6FB2374A85D93C7FFE9CCAD1231BE866F5FE69255312CE85B9FF

func (SM2) FromPublicKeyDer added in v1.0.2015

func (this SM2) FromPublicKeyDer(der []byte) SM2

DER 公钥

func (SM2) FromPublicKeyString

func (this SM2) FromPublicKeyString(key string) SM2

公钥明文

func (SM2) FromPublicKeyUncompressString added in v1.0.2027

func (this SM2) FromPublicKeyUncompressString(keyString string) SM2

公钥明文未压缩 (hexStringX + hexStringY) public-key: 047c********.

func (SM2) FromPublicKeyXYBytes

func (this SM2) FromPublicKeyXYBytes(XBytes, YBytes []byte) SM2

公钥 x,y 字节对

func (SM2) FromPublicKeyXYString added in v1.0.1018

func (this SM2) FromPublicKeyXYString(xString, yString string) SM2

公钥 x,y 16进制字符对 [xString: xHexString, yString: yHexString]

func (SM2) FromString

func (this SM2) FromString(data string) SM2

字符

func (SM2) GenerateKey

func (this SM2) GenerateKey() SM2

生成密钥对

func (SM2) GenerateKeyWithSeed added in v1.0.2026

func (this SM2) GenerateKeyWithSeed(reader io.Reader) SM2

使用自定义数据生成密钥对

func (SM2) GetData

func (this SM2) GetData() []byte

get data

func (SM2) GetEncoding added in v1.0.3009

func (this SM2) GetEncoding() EncodingType

get Encoding type

func (SM2) GetErrors added in v1.0.1026

func (this SM2) GetErrors() []error

get errors

func (SM2) GetKeyData

func (this SM2) GetKeyData() []byte

get key Data

func (SM2) GetMode added in v1.0.1041

func (this SM2) GetMode() sm2.Mode

get mode

func (SM2) GetParsedData added in v1.0.2049

func (this SM2) GetParsedData() []byte

get parsedData

func (SM2) GetPrivateKey

func (this SM2) GetPrivateKey() *sm2.PrivateKey

get PrivateKey

func (SM2) GetPrivateKeyCurve

func (this SM2) GetPrivateKeyCurve() elliptic.Curve

get PrivateKey Curve

func (SM2) GetPrivateKeyDString added in v1.0.2071

func (this SM2) GetPrivateKeyDString() string

get PrivateKey D hex string

func (SM2) GetPrivateKeyString added in v1.0.2027

func (this SM2) GetPrivateKeyString() string

get PrivateKey data hex string

func (SM2) GetPublicKey

func (this SM2) GetPublicKey() *sm2.PublicKey

get PublicKey

func (SM2) GetPublicKeyCompressString added in v1.0.2027

func (this SM2) GetPublicKeyCompressString() string

get PublicKey Compress Hex string

func (SM2) GetPublicKeyCurve

func (this SM2) GetPublicKeyCurve() elliptic.Curve

get PublicKey Curve

func (SM2) GetPublicKeyUncompressString added in v1.0.2027

func (this SM2) GetPublicKeyUncompressString() string

get PublicKey Uncompress Hex string

func (SM2) GetPublicKeyXString added in v1.0.2071

func (this SM2) GetPublicKeyXString() string

get PublicKey X hex string

func (SM2) GetPublicKeyXYString added in v1.0.2071

func (this SM2) GetPublicKeyXYString() string

get PublicKey X and Y Hex string

func (SM2) GetPublicKeyYString added in v1.0.2071

func (this SM2) GetPublicKeyYString() string

get PublicKey Y hex string

func (SM2) GetUID added in v1.0.2049

func (this SM2) GetUID() []byte

get uid

func (SM2) GetVerify added in v1.0.1032

func (this SM2) GetVerify() bool

get verify data

func (SM2) MakeKeyDer added in v1.0.1033

func (this SM2) MakeKeyDer() SM2

生成密钥 der 数据

func (SM2) MakePublicKey

func (this SM2) MakePublicKey() SM2

生成公钥

func (SM2) OnError

func (this SM2) OnError(fn SM2ErrorFunc) SM2

引出错误信息

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 (this SM2) ParsePublicKeyFromPEM(key []byte) (*sm2.PublicKey, error)

解析公钥

func (SM2) SetMode added in v1.0.1041

func (this SM2) SetMode(data string) SM2

设置 mode C1C3C2 = 0 | C1C2C3 = 1

func (SM2) SetSignHash added in v1.0.2048

func (this SM2) SetSignHash(data string) SM2

设置 hash 类型 可用参数可查看 Hash 结构体数据

func (SM2) SetUID added in v1.0.2049

func (this SM2) SetUID(data string) SM2

设置 uid

func (SM2) Sign

func (this SM2) Sign() SM2

私钥签名

func (SM2) SignASN1 added in v1.0.2039

func (this SM2) SignASN1() SM2

私钥签名 ASN1

func (SM2) SignBytes added in v1.0.2039

func (this SM2) SignBytes() SM2

私钥签名 Bytes 兼容[招行]

func (SM2) ToBase64String

func (this SM2) ToBase64String() string

输出Base64

func (SM2) ToBytes

func (this SM2) ToBytes() []byte

输出字节

func (SM2) ToHexString

func (this SM2) ToHexString() string

输出Hex

func (SM2) ToKeyBytes

func (this SM2) ToKeyBytes() []byte

私钥/公钥

func (SM2) ToKeyString

func (this SM2) ToKeyString() string

私钥/公钥

func (SM2) ToString

func (this SM2) ToString() string

输出字符

func (SM2) ToVerify added in v1.0.1032

func (this SM2) ToVerify() bool

验证结果

func (SM2) ToVerifyInt added in v1.0.1033

func (this SM2) ToVerifyInt() int

验证结果,返回 int 类型

func (SM2) Verify added in v1.0.1033

func (this SM2) Verify(data []byte) SM2

公钥验证 使用原始数据[data]对比签名后数据

func (SM2) VerifyASN1 added in v1.0.2039

func (this SM2) VerifyASN1(data []byte) SM2

公钥验证 ASN1 使用原始数据[data]对比签名后数据

func (SM2) VerifyBytes added in v1.0.2039

func (this SM2) VerifyBytes(data []byte) SM2

公钥验证 Bytes 兼容[招行] 使用原始数据[data]对比签名后数据

func (SM2) WithData

func (this SM2) WithData(data []byte) SM2

设置 data

func (SM2) WithEncoding added in v1.0.3009

func (this SM2) WithEncoding(encoding EncodingType) SM2

设置编码方式

func (SM2) WithEncodingASN1 added in v1.0.3009

func (this SM2) WithEncodingASN1() SM2

设置 ASN1 编码方式

func (SM2) WithEncodingBytes added in v1.0.3009

func (this SM2) WithEncodingBytes() SM2

设置明文编码方式

func (SM2) WithErrors added in v1.0.1026

func (this SM2) WithErrors(errs []error) SM2

设置错误

func (SM2) WithMode added in v1.0.1041

func (this SM2) WithMode(data sm2.Mode) SM2

设置 mode

func (SM2) WithParsedData added in v1.0.2049

func (this SM2) WithParsedData(data []byte) SM2

设置 parsedData

func (SM2) WithPrivateKey

func (this SM2) WithPrivateKey(data *sm2.PrivateKey) SM2

设置 PrivateKey

func (SM2) WithPublicKey

func (this SM2) WithPublicKey(data *sm2.PublicKey) SM2

设置 PublicKey

func (SM2) WithSignHash added in v1.0.2048

func (this SM2) WithSignHash(data HashFunc) SM2

设置 hash 类型

func (SM2) WithUID added in v1.0.2049

func (this SM2) WithUID(data []byte) SM2

设置 uid

func (SM2) WithVerify added in v1.0.1032

func (this SM2) WithVerify(data bool) SM2

设置 verify

type SM2ErrorFunc

type SM2ErrorFunc = func([]error)

错误方法

type ScryptOpts added in v1.0.1028

type ScryptOpts = pkcs8.ScryptOpts

Scrypt 配置

Jump to

Keyboard shortcuts

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