primitive

package
v0.0.0-...-dc235c6 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2020 License: Apache-2.0 Imports: 6 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context interface {
	KeysGenerator
	Sm2Crypto
	Sm3Crypro
	Sm4Crypro
}

国密套件所有功能接口

type KeysGenerator

type KeysGenerator interface {
	// 生成sm2公私钥对
	GenPrivateKey() (*Sm2PrivateKey, error)
	// 从sm2私钥导出公钥
	PublicKey(k *Sm2PrivateKey) *Sm2PublicKey
	// 从未加密的pkcs8数据解析出sm2私钥
	ParsePKCS8UnecryptedPrivateKey(der []byte) (*Sm2PrivateKey, error)
	// 从加密的pkcs8数据解析出sm2私钥
	ParsePKCS8PrivateKey(der, pwd []byte) (*Sm2PrivateKey, error)
	// 根据给定密钥,加密sm2私钥,输出ASN.1编码数据
	MarshalSm2PrivateKey(k *Sm2PrivateKey, pwd []byte) ([]byte, error)
	// 从ASN.1编码数据解析出sm2公钥
	ParseSm2PublicKey(der []byte) (*Sm2PublicKey, error)
	// 序列化sm2私钥,输出ASN.1编码数据
	MarshalSm2PublicKey(k *Sm2PublicKey) ([]byte, error)
}

type Sm2Crypto

type Sm2Crypto interface {
	// 签名验证,验证成功返回true,error为nil; 验证失败返回false,并返回错误信息
	Verify(k *Sm2PublicKey, sig, msg []byte, opts crypto.SignerOpts) (bool, error)
	// 数据签名, 成功返回数字签名,error为nil; 失败返回nil,并返回错误信息
	Sign(k *Sm2PrivateKey, msg []byte, opts crypto.SignerOpts) ([]byte, error)
	// 数据加密, 成功返回密文,error为nil; 失败返回nil,并返回错误信息
	Encrypt(k *Sm2PublicKey, plaintext []byte) ([]byte, error)
	// 数据解密,成功返回明文,error为nil; 失败返回nil,并返回错误信息
	Decrypt(k *Sm2PrivateKey, ciphertext []byte, opts crypto.DecrypterOpts) ([]byte, error)
	// 返回sm2算法使用的椭圆曲线
	Sm2P256Curve() elliptic.Curve
}

type Sm2PrivateKey

type Sm2PrivateKey struct {
	Sm2PublicKey
	D *big.Int
}

sm2私钥,与ecdsa私钥结构一致,用来统一sm2私钥结构,其他国密实现的sm2私钥可以统一转换成该结构体

func (*Sm2PrivateKey) Public

func (s *Sm2PrivateKey) Public() crypto.PublicKey

返回sm2私钥对应的公钥

func (*Sm2PrivateKey) Sign

func (s *Sm2PrivateKey) Sign(rand io.Reader, digest []byte, opts crypto.SignerOpts) (signature []byte, err error)

该方法尚未实现,由于可能对应多种不同类型私钥的签名方法,无法统一,签名方法使用 Sm2Crypto.Sign 函数

type Sm2PublicKey

type Sm2PublicKey struct {
	elliptic.Curve
	X, Y *big.Int
}

sm2公钥,与ecdsa公钥结构一致,用来统一sm2公钥结构,其他国密实现的sm2公钥可以统一转换成该结构体

type Sm3Crypro

type Sm3Crypro interface {
	// 创建sm3实例,返回hash函数接口
	NewSm3() hash.Hash
}

type Sm4Crypro

type Sm4Crypro interface {
	// 根据给定密钥创建sm4分组加密实例,返回分组加密功能函数接口
	NewSm4Cipher(key []byte) (cipher.Block, error)
}

Jump to

Keyboard shortcuts

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