sm2

package
v1.0.2014 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2023 License: Apache-2.0 Imports: 13 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// 获取 Cipher 类型
	GetCipherFromName = cryptobin_pkcs8.GetCipherFromName
	// 获取 hash 类型
	GetHashFromName = cryptobin_pkcs8.GetHashFromName
)
View Source
var (
	ErrKeyMustBePEMEncoded = errors.New("invalid key: Key must be a PEM encoded PKCS1 or PKCS8 key")
)

Functions

This section is empty.

Types

type Opts added in v1.0.1028

type Opts = cryptobin_pkcs8.Opts

配置

type PBKDF2Opts added in v1.0.1028

type PBKDF2Opts = cryptobin_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

Hex

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 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) 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 数据 使用: 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) CreateSM2PrivateKeyWithPassword added in v1.0.1028

func (this SM2) CreateSM2PrivateKeyWithPassword(password string) SM2

生成私钥带密码 pem 数据

func (SM2) Decrypt

func (this SM2) Decrypt() SM2

私钥解密

func (SM2) DecryptAsn1 added in v1.0.1041

func (this SM2) DecryptAsn1(pub *sm2.PrivateKey, data []byte, mode int) ([]byte, error)

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

func (SM2) Encrypt

func (this SM2) Encrypt() SM2

公钥加密

func (SM2) EncryptAsn1 added in v1.0.1041

func (this SM2) EncryptAsn1(pub *sm2.PublicKey, data []byte, mode int, rand io.Reader) ([]byte, error)

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

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

Hex

func (SM2) FromPrivateKey

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

私钥

func (SM2) FromPrivateKeyBytes

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

明文私钥生成私钥结构体

func (SM2) FromPrivateKeyDBytes

func (this SM2) FromPrivateKeyDBytes(DBytes []byte) SM2

私钥字符,必须先添加公钥

func (SM2) FromPrivateKeyString

func (this SM2) FromPrivateKeyString(keyString string) SM2

私钥字符,必须先添加公钥 (hexStringD) 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) FromPublicKeyString

func (this SM2) FromPublicKeyString(keyString string) SM2

公钥字符 (hexStringX + hexStringY) public-key: 047c********.

func (SM2) FromPublicKeyXYBytes

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

公钥字符对

func (SM2) FromPublicKeyXYString added in v1.0.1018

func (this SM2) FromPublicKeyXYString(xString string, 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) GetData

func (this SM2) GetData() []byte

获取 data

func (SM2) GetErrors added in v1.0.1026

func (this SM2) GetErrors() []error

获取错误

func (SM2) GetKeyData

func (this SM2) GetKeyData() []byte

获取 keyData

func (SM2) GetMode added in v1.0.1041

func (this SM2) GetMode() int

获取 mode

func (SM2) GetParedData

func (this SM2) GetParedData() []byte

获取 paredData

func (SM2) GetPrivateKey

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

获取 PrivateKey

func (SM2) GetPrivateKeyCurve

func (this SM2) GetPrivateKeyCurve() elliptic.Curve

获取 PrivateKeyCurve

func (SM2) GetPrivateKeyDHexString added in v1.0.1018

func (this SM2) GetPrivateKeyDHexString() string

获取 PrivateKeyD

func (SM2) GetPrivateKeyXHexString added in v1.0.1018

func (this SM2) GetPrivateKeyXHexString() string

获取 PrivateKeyX

func (SM2) GetPrivateKeyYHexString added in v1.0.1018

func (this SM2) GetPrivateKeyYHexString() string

获取 PrivateKeyY

func (SM2) GetPublicKey

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

获取 PublicKey

func (SM2) GetPublicKeyCurve

func (this SM2) GetPublicKeyCurve() elliptic.Curve

获取 PublicKeyCurve

func (SM2) GetPublicKeyXHexString added in v1.0.1018

func (this SM2) GetPublicKeyXHexString() string

获取 PublicKeyX

func (SM2) GetPublicKeyYHexString added in v1.0.1018

func (this SM2) GetPublicKeyYHexString() string

获取 PublicKeyY

func (SM2) GetVerify added in v1.0.1032

func (this SM2) GetVerify() bool

获取验证后情况

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) ParsePKCS8PrivateKeyFromPEMWithPassword added in v1.0.1028

func (this SM2) ParsePKCS8PrivateKeyFromPEMWithPassword(key []byte, password string) (*sm2.PrivateKey, error)

解析 PSM2 KCS8 带密码的私钥

func (SM2) ParsePrivateKeyFromPEM

func (this SM2) ParsePrivateKeyFromPEM(key []byte) (*sm2.PrivateKey, error)

解析 SM2 PKCS8 私钥

func (SM2) ParsePrivateKeyFromPEMWithPassword

func (this SM2) ParsePrivateKeyFromPEMWithPassword(key []byte, password string) (*sm2.PrivateKey, error)

解析 SM2 PKCS8 私钥带密码

func (SM2) ParsePublicKeyFromPEM

func (this SM2) ParsePublicKeyFromPEM(key []byte) (*sm2.PublicKey, error)

解析 SM2 PKCS8 公钥

func (SM2) SetMode added in v1.0.1041

func (this SM2) SetMode(data string) SM2

设置 mode C1C3C2 = 0 | C1C2C3 = 1

func (SM2) Sign

func (this SM2) Sign() SM2

私钥签名

func (SM2) SignAsn1

func (this SM2) SignAsn1(uid []byte) SM2

私钥签名

func (SM2) SignHex

func (this SM2) SignHex(uid []byte) SM2

私钥签名 兼容[招行]

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

func (this SM2) VerifyAsn1(data []byte, uid []byte) SM2

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

func (SM2) VerifyHex

func (this SM2) VerifyHex(data []byte, uid []byte) SM2

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

func (SM2) WithData

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

设置 data

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 int) SM2

设置 mode

func (SM2) WithParedData

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

设置 paredData

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) 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 = cryptobin_pkcs8.ScryptOpts

Scrypt 配置

Jump to

Keyboard shortcuts

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