ecdh

package
v1.0.1025 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2022 License: Apache-2.0 Imports: 9 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 ecdh private key")
	ErrNotPublicKey        = errors.New("key is not a valid ecdh public key")
)
View Source
var PEMCiphers = map[string]x509.PEMCipher{
	"DESCBC":     x509.PEMCipherDES,
	"DESEDE3CBC": x509.PEMCipher3DES,
	"AES128CBC":  x509.PEMCipherAES128,
	"AES192CBC":  x509.PEMCipherAES192,
	"AES256CBC":  x509.PEMCipherAES256,
}

pem 加密方式

Functions

func GetCurveFromName added in v1.0.1025

func GetCurveFromName(name string) ecdh.Curve

获取 Curve

Types

type Ecdh

type Ecdh struct {

	// 错误
	Error error
	// contains filtered or unexported fields
}

*

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

func New

func New() Ecdh

构造函数

func NewEcdh

func NewEcdh() Ecdh

构造函数

func (Ecdh) CreateKdfPrivateKeyWithPassword

func (this Ecdh) CreateKdfPrivateKeyWithPassword(password string, opts ...any) Ecdh

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

func (Ecdh) CreatePbePrivateKeyWithPassword

func (this Ecdh) CreatePbePrivateKeyWithPassword(password string, alg string) Ecdh

生成 PKCS8 私钥带密码 pem 数据

func (Ecdh) CreatePrivateKey

func (this Ecdh) CreatePrivateKey() Ecdh

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

func (Ecdh) CreatePrivateKeyWithPassword

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

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

func (Ecdh) CreatePublicKey

func (this Ecdh) CreatePublicKey() Ecdh

生成公钥 pem 数据

func (Ecdh) CreateSecret

func (this Ecdh) CreateSecret() Ecdh

根据公钥和私钥生成密钥

func (Ecdh) FromKeyXYHexString added in v1.0.1025

func (this Ecdh) FromKeyXYHexString(curve string, xString string, yString string) Ecdh

根据私钥 x, y 生成

func (Ecdh) FromPrivateKey

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

私钥

func (Ecdh) FromPrivateKeyWithPassword

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

私钥带密码

func (Ecdh) FromPrivateKeyXHexString added in v1.0.1025

func (this Ecdh) FromPrivateKeyXHexString(curve string, xString string) Ecdh

根据私钥 x 生成

func (Ecdh) FromPublicKey

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

公钥

func (Ecdh) FromPublicKeyYHexString added in v1.0.1025

func (this Ecdh) FromPublicKeyYHexString(curve string, yString string) Ecdh

根据公钥 y 生成

func (Ecdh) GenerateKey

func (this Ecdh) GenerateKey(curve string) Ecdh

生成密钥 可用参数 [P521 | P384 | P256 | P224]

func (Ecdh) GetError

func (this Ecdh) GetError() error

获取错误

func (Ecdh) GetKeyData

func (this Ecdh) GetKeyData() []byte

获取 keyData

func (Ecdh) GetPrivateKey

func (this Ecdh) GetPrivateKey() *ecdh.PrivateKey

获取 PrivateKey

func (Ecdh) GetPrivateKeyXHexString added in v1.0.1025

func (this Ecdh) GetPrivateKeyXHexString() string

获取 X 16进制字符

func (Ecdh) GetPublicKey

func (this Ecdh) GetPublicKey() *ecdh.PublicKey

获取 PublicKey

func (Ecdh) GetPublicKeyYHexString added in v1.0.1025

func (this Ecdh) GetPublicKeyYHexString() string

获取 Y 16进制字符

func (Ecdh) MakePublicKey

func (this Ecdh) MakePublicKey() Ecdh

生成公钥

func (Ecdh) OnError

func (this Ecdh) OnError(fn ErrorFunc) Ecdh

引出错误信息

func (Ecdh) ParsePrivateKeyFromPEM

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

解析私钥

func (Ecdh) ParsePrivateKeyFromPEMWithPassword

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

解析私钥带密码

func (Ecdh) ParsePublicKeyFromPEM

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

解析公钥

func (Ecdh) ToBase64String

func (this Ecdh) ToBase64String() string

输出Base64

func (Ecdh) ToBytes

func (this Ecdh) ToBytes() []byte

输出字节

func (Ecdh) ToHexString

func (this Ecdh) ToHexString() string

输出Hex

func (Ecdh) ToKeyBytes

func (this Ecdh) ToKeyBytes() []byte

私钥/公钥

func (Ecdh) ToKeyString

func (this Ecdh) ToKeyString() string

私钥/公钥

func (Ecdh) ToString

func (this Ecdh) ToString() string

输出字符

func (Ecdh) WithError

func (this Ecdh) WithError(err error) Ecdh

设置错误

func (Ecdh) WithKeyData

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

设置 keyData

func (Ecdh) WithPrivateKey

func (this Ecdh) WithPrivateKey(data *ecdh.PrivateKey) Ecdh

设置 PrivateKey

func (Ecdh) WithPublicKey

func (this Ecdh) WithPublicKey(data *ecdh.PublicKey) Ecdh

设置 PublicKey

type ErrorFunc

type ErrorFunc = func(error)

错误方法

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