dh

package
v1.0.2019 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

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")
	ErrNotPrivateKey       = errors.New("key is not a valid dh private key")
	ErrNotPublicKey        = errors.New("key is not a valid dh public key")
)

Functions

func RandomString added in v1.0.1028

func RandomString(n int64, allowedChars ...[]rune) string

生成随机字符

Types

type Dh

type Dh struct {

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

*

  • dh *
  • @create 2022-8-7
  • @author deatil

func FromKeyXYHexString added in v1.0.2014

func FromKeyXYHexString(xString string, yString string) Dh

根据私钥 x, y 生成

func FromPrivateKey added in v1.0.2014

func FromPrivateKey(key []byte) Dh

私钥

func FromPrivateKeyWithPassword added in v1.0.2014

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

私钥

func FromPrivateKeyXHexString added in v1.0.2014

func FromPrivateKeyXHexString(xString string) Dh

根据私钥 x 生成

func FromPublicKey added in v1.0.2014

func FromPublicKey(key []byte) Dh

公钥

func FromPublicKeyYHexString added in v1.0.2014

func FromPublicKeyYHexString(yString string) Dh

根据公钥 y 生成

func GenerateKey added in v1.0.2014

func GenerateKey() Dh

生成密钥

func New

func New() Dh

构造函数

func NewDH added in v1.0.2014

func NewDH() Dh

构造函数

func (Dh) AppendError added in v1.0.1026

func (this Dh) AppendError(err ...error) Dh

添加错误

func (Dh) CheckKeyPair added in v1.0.1046

func (this Dh) CheckKeyPair() bool

检测公钥私钥是否匹配

func (Dh) CreatePrivateKey

func (this Dh) CreatePrivateKey() Dh

生成私钥 pem 数据 使用: obj := New().GenerateKey("P2048") priKey := obj.CreatePrivateKey().ToKeyString()

func (Dh) CreatePrivateKeyWithPassword

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

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

func (Dh) CreatePublicKey

func (this Dh) CreatePublicKey() Dh

生成公钥 pem 数据

func (Dh) CreateSecretKey added in v1.0.1038

func (this Dh) CreateSecretKey() Dh

根据公钥和私钥生成密钥

func (Dh) Error

func (this Dh) Error() error

获取错误

func (Dh) FromKeyXYHexString added in v1.0.1025

func (this Dh) FromKeyXYHexString(xString string, yString string) Dh

根据密钥 x, y 生成

func (Dh) FromPrivateKey

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

私钥

func (Dh) FromPrivateKeyDer added in v1.0.2015

func (this Dh) FromPrivateKeyDer(der []byte) Dh

DER 私钥

func (Dh) FromPrivateKeyWithPassword

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

私钥带密码

func (Dh) FromPrivateKeyXHexString added in v1.0.1025

func (this Dh) FromPrivateKeyXHexString(xString string) Dh

根据私钥 x 生成

func (Dh) FromPublicKey

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

公钥

func (Dh) FromPublicKeyDer added in v1.0.2015

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

DER 公钥

func (Dh) FromPublicKeyYHexString added in v1.0.1025

func (this Dh) FromPublicKeyYHexString(yString string) Dh

根据公钥 y 生成

func (Dh) GenerateKey

func (this Dh) GenerateKey() Dh

生成密钥

func (Dh) GetErrors added in v1.0.1026

func (this Dh) GetErrors() []error

获取错误

func (Dh) GetGroup added in v1.0.1026

func (this Dh) GetGroup() *dh.Group

获取分组

func (Dh) GetKeyData

func (this Dh) GetKeyData() []byte

获取 keyData

func (Dh) GetPrivateKey

func (this Dh) GetPrivateKey() *dh.PrivateKey

获取 PrivateKey

func (Dh) GetPrivateKeyXHexString added in v1.0.1025

func (this Dh) GetPrivateKeyXHexString() string

获取 X 16进制字符

func (Dh) GetPublicKey

func (this Dh) GetPublicKey() *dh.PublicKey

获取 PublicKey

func (Dh) GetPublicKeyParametersGHexString added in v1.0.1025

func (this Dh) GetPublicKeyParametersGHexString() string

获取 G 16进制字符

func (Dh) GetPublicKeyParametersPHexString added in v1.0.1025

func (this Dh) GetPublicKeyParametersPHexString() string

获取 P 16进制字符

func (Dh) GetPublicKeyYHexString added in v1.0.1025

func (this Dh) GetPublicKeyYHexString() string

获取 Y 16进制字符

func (Dh) GetSecretData added in v1.0.1026

func (this Dh) GetSecretData() []byte

获取 secretData

func (Dh) MakeKeyDer added in v1.0.1033

func (this Dh) MakeKeyDer() Dh

生成密钥 der 数据

func (Dh) MakePublicKey

func (this Dh) MakePublicKey() Dh

生成公钥

func (Dh) OnError

func (this Dh) OnError(fn ErrorFunc) Dh

引出错误信息

func (Dh) ParsePrivateKeyFromPEM

func (this Dh) ParsePrivateKeyFromPEM(key []byte) (crypto.PrivateKey, error)

解析私钥

func (Dh) ParsePrivateKeyFromPEMWithPassword

func (this Dh) ParsePrivateKeyFromPEMWithPassword(key []byte, password string) (crypto.PrivateKey, error)

解析私钥带密码

func (Dh) ParsePublicKeyFromPEM

func (this Dh) ParsePublicKeyFromPEM(key []byte) (crypto.PublicKey, error)

解析公钥

func (Dh) SetGroup added in v1.0.1026

func (this Dh) SetGroup(name string) Dh

根据 Group 数据设置分组

func (Dh) SetGroupPG added in v1.0.1027

func (this Dh) SetGroupPG(p string, g int64) Dh

根据 Group P和G 数据设置分组

func (Dh) SetRandGroup added in v1.0.1027

func (this Dh) SetRandGroup(num int64) Dh

随机数

func (Dh) ToBase64String

func (this Dh) ToBase64String() string

输出Base64

func (Dh) ToBytes

func (this Dh) ToBytes() []byte

输出字节

func (Dh) ToHexString

func (this Dh) ToHexString() string

输出Hex

func (Dh) ToKeyBytes

func (this Dh) ToKeyBytes() []byte

私钥/公钥

func (Dh) ToKeyString

func (this Dh) ToKeyString() string

私钥/公钥

func (Dh) ToString

func (this Dh) ToString() string

输出字符

func (Dh) WithError

func (this Dh) WithError(errs []error) Dh

设置错误

func (Dh) WithGroup added in v1.0.1026

func (this Dh) WithGroup(data *dh.Group) Dh

设置分组

func (Dh) WithKeyData

func (this Dh) WithKeyData(data []byte) Dh

设置 keyData

func (Dh) WithPrivateKey

func (this Dh) WithPrivateKey(data *dh.PrivateKey) Dh

设置 PrivateKey

func (Dh) WithPublicKey

func (this Dh) WithPublicKey(data *dh.PublicKey) Dh

设置 PublicKey

func (Dh) WithSecretData added in v1.0.1026

func (this Dh) WithSecretData(data []byte) Dh

设置 secretData

type ErrorFunc

type ErrorFunc = func([]error)

错误方法

type Group added in v1.0.1025

type Group = cryptobin_dh.Group

Group 别名

type Opts

type Opts = cryptobin_pkcs8.Opts

配置

type PBKDF2Opts

type PBKDF2Opts = cryptobin_pkcs8.PBKDF2Opts

PBKDF2 配置

type ScryptOpts

type ScryptOpts = cryptobin_pkcs8.ScryptOpts

Scrypt 配置

Jump to

Keyboard shortcuts

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