ecdh

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

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

Functions

This section is empty.

Types

type ECDH

type ECDH struct {

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

*

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

func FromKeyXYString

func FromKeyXYString(xString string, yString string) ECDH

根据私钥 x, y 生成

func FromPrivateKey

func FromPrivateKey(key []byte) ECDH

私钥

func FromPrivateKeyWithPassword

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

私钥

func FromPrivateKeyXString

func FromPrivateKeyXString(xString string) ECDH

根据私钥 x 生成

func FromPublicKey

func FromPublicKey(key []byte) ECDH

公钥

func FromPublicKeyYString

func FromPublicKeyYString(yString string) ECDH

根据公钥 y 生成

func GenerateKey

func GenerateKey(curve string) ECDH

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

func GenerateKeyWithSeed

func GenerateKeyWithSeed(reader io.Reader, curve string) ECDH

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

func New

func New() ECDH

构造函数

func NewEcdh

func NewEcdh() ECDH

构造函数

func (ECDH) AppendError

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

添加错误

func (ECDH) CheckKeyPair

func (this ECDH) CheckKeyPair() bool

检测公钥私钥是否匹配

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) CreateSecretKey

func (this ECDH) CreateSecretKey() ECDH

根据公钥和私钥生成密钥

func (ECDH) Error

func (this ECDH) Error() error

获取错误

func (ECDH) FromKeyXYString

func (this ECDH) FromKeyXYString(xString string, yString string) ECDH

根据私钥 x, y 生成

func (ECDH) FromPrivateKey

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

私钥

func (ECDH) FromPrivateKeyDer

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

DER 私钥

func (ECDH) FromPrivateKeyWithPassword

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

私钥带密码

func (ECDH) FromPrivateKeyXString

func (this ECDH) FromPrivateKeyXString(xString string) ECDH

根据私钥 x 生成

func (ECDH) FromPublicKey

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

公钥

func (ECDH) FromPublicKeyDer

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

DER 公钥

func (ECDH) FromPublicKeyYString

func (this ECDH) FromPublicKeyYString(yString string) ECDH

根据公钥 y 生成

func (ECDH) GenerateKey

func (this ECDH) GenerateKey() ECDH

生成密钥

func (ECDH) GenerateKeyWithSeed

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

生成密钥

func (ECDH) GetCurve

func (this ECDH) GetCurve() ecdh.Curve

获取散列方式

func (ECDH) GetErrors

func (this ECDH) GetErrors() []error

获取错误

func (ECDH) GetKeyData

func (this ECDH) GetKeyData() []byte

获取 keyData

func (ECDH) GetPrivateKey

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

获取 PrivateKey

func (ECDH) GetPrivateKeyXString

func (this ECDH) GetPrivateKeyXString() string

获取 X 16进制字符

func (ECDH) GetPublicKey

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

获取 PublicKey

func (ECDH) GetPublicKeyYString

func (this ECDH) GetPublicKeyYString() string

获取 Y 16进制字符

func (ECDH) GetSecretData

func (this ECDH) GetSecretData() []byte

获取 secretData

func (ECDH) MakeKeyDer

func (this ECDH) MakeKeyDer() ECDH

生成密钥 der 数据

func (ECDH) MakePublicKey

func (this ECDH) MakePublicKey() ECDH

生成公钥

func (ECDH) OnError

func (this ECDH) OnError(fn func([]error)) 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) SetCurve

func (this ECDH) SetCurve(name string) ECDH

设置散列方式 可用参数 [P521 | P384 | P256 | P224]

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) WithCurve

func (this ECDH) WithCurve(data ecdh.Curve) ECDH

设置散列方式

func (ECDH) WithErrors

func (this ECDH) WithErrors(errs []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

func (ECDH) WithSecretData

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

设置 secretData

type Opts

type Opts = pkcs8.Opts

配置

type PBKDF2Opts

type PBKDF2Opts = pkcs8.PBKDF2Opts

PBKDF2 配置

type ScryptOpts

type ScryptOpts = pkcs8.ScryptOpts

Scrypt 配置

Jump to

Keyboard shortcuts

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