jceks

package
v1.0.1036 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2022 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CipherMD5And3DES = CipherBlockCBC{
	// contains filtered or unexported fields
}
View Source
var CipherSHA1And3DES = CipherBlockCBC{
	// contains filtered or unexported fields
}
View Source
var DefaultCipher = CipherMD5And3DES

默认配置

View Source
var LoadFromBytes = LoadJceksFromBytes
View Source
var LoadFromReader = LoadJceksFromReader

别名

View Source
var NewJceksEncode = NewJCEKS
View Source
var NewJksEncode = NewJKS

编码

Functions

func AddCipher

func AddCipher(oid asn1.ObjectIdentifier, cipher func() Cipher)

添加加密

func AddKey

func AddKey(name string, key func() Key)

添加Key

func DecodeData

func DecodeData(encodedData, password []byte) ([]byte, error)

解密数据

func DecryptedPrivateKeyInfo

func DecryptedPrivateKeyInfo(data []byte) ([]byte, error)

解密数据

func EncodeData

func EncodeData(data []byte, password string, cipher ...Cipher) ([]byte, error)

加密数据

func EncryptedPrivateKeyInfo

func EncryptedPrivateKeyInfo(algorithm asn1.ObjectIdentifier, data []byte) ([]byte, error)

加密数据

func GetStructName

func GetStructName(name any) string

反射获取结构体名称

func MarshalPKCS8PrivateKey

func MarshalPKCS8PrivateKey(privateKey crypto.PrivateKey) ([]byte, error)

从注册的 key 列表编码证书

func ParsePKCS8PrivateKey

func ParsePKCS8PrivateKey(pkData []byte) (privateKey crypto.PrivateKey, err error)

从注册的 key 列表解析证书

Types

type Cipher

type Cipher interface {
	// oid
	OID() asn1.ObjectIdentifier

	// 值大小
	KeySize() int

	// 加密, 返回: [加密后数据, 参数, error]
	Encrypt(key, plaintext []byte) ([]byte, []byte, error)

	// 解密
	Decrypt(key, params, ciphertext []byte) ([]byte, error)
}

加密接口

type CipherBlockCBC

type CipherBlockCBC struct {
	// contains filtered or unexported fields
}

cbc 模式加密

func (CipherBlockCBC) Decrypt

func (this CipherBlockCBC) Decrypt(password, params, ciphertext []byte) ([]byte, error)

解密

func (CipherBlockCBC) Encrypt

func (this CipherBlockCBC) Encrypt(password, plaintext []byte) ([]byte, []byte, error)

加密

func (CipherBlockCBC) KeySize

func (this CipherBlockCBC) KeySize() int

值大小

func (CipherBlockCBC) OID

oid

func (CipherBlockCBC) WithSaltSize

func (this CipherBlockCBC) WithSaltSize(saltSize int) CipherBlockCBC

设置 saltSize

type JCEKS added in v1.0.1036

type JCEKS struct {
	// contains filtered or unexported fields
}

编码

func LoadJceksFromBytes

func LoadJceksFromBytes(data []byte, password string) (*JCEKS, error)

LoadJceksFromBytes loads the key store from the bytes data.

func LoadJceksFromReader

func LoadJceksFromReader(reader io.Reader, password string) (*JCEKS, error)

LoadJceksFromReader loads the key store from the specified file.

func NewJCEKS added in v1.0.1036

func NewJCEKS() *JCEKS

构造函数

func (*JCEKS) AddPrivateKey added in v1.0.1036

func (this *JCEKS) AddPrivateKey(
	alias string,
	privateKey crypto.PrivateKey,
	password string,
	certs [][]byte,
	cipher ...Cipher,
) error

添加私钥

func (*JCEKS) AddSecretKey added in v1.0.1036

func (this *JCEKS) AddSecretKey(
	alias string,
	secretKey []byte,
	password string,
	cipher ...Cipher,
) error

添加密钥

func (*JCEKS) AddTrustedCert added in v1.0.1036

func (this *JCEKS) AddTrustedCert(
	alias string,
	cert []byte,
	cipher ...Cipher,
) error

添加证书

func (*JCEKS) GetCert added in v1.0.1036

func (this *JCEKS) GetCert(alias string) (*x509.Certificate, error)

GetCert

func (*JCEKS) GetCertBytes added in v1.0.1036

func (this *JCEKS) GetCertBytes(alias string) ([]byte, error)

GetCertBytes

func (*JCEKS) GetPrivateKeyAndCerts added in v1.0.1036

func (this *JCEKS) GetPrivateKeyAndCerts(alias string, password string) (
	key crypto.PrivateKey,
	certs []*x509.Certificate,
	err error,
)

GetPrivateKeyAndCerts

func (*JCEKS) GetPrivateKeyAndCertsBytes added in v1.0.1036

func (this *JCEKS) GetPrivateKeyAndCertsBytes(alias string, password string) (
	key crypto.PrivateKey,
	certs [][]byte,
	err error,
)

GetPrivateKeyAndCertsBytes

func (*JCEKS) GetSecretKey added in v1.0.1036

func (this *JCEKS) GetSecretKey(alias string, password string) (key []byte, err error)

GetSecretKey

func (*JCEKS) ListCerts added in v1.0.1036

func (this *JCEKS) ListCerts() []string

ListCerts

func (*JCEKS) ListPrivateKeys added in v1.0.1036

func (this *JCEKS) ListPrivateKeys() []string

ListPrivateKeys

func (*JCEKS) ListSecretKeys added in v1.0.1036

func (this *JCEKS) ListSecretKeys() []string

ListSecretKeys lists the names of the SecretKey stored in the key store.

func (*JCEKS) Marshal added in v1.0.1036

func (this *JCEKS) Marshal(password string) ([]byte, error)

func (*JCEKS) Parse added in v1.0.1036

func (this *JCEKS) Parse(r io.Reader, password string) error

解析

func (*JCEKS) String added in v1.0.1036

func (this *JCEKS) String() string

type JKS added in v1.0.1036

type JKS struct {
	// contains filtered or unexported fields
}

Jks

func LoadJksFromBytes

func LoadJksFromBytes(data []byte, password string) (*JKS, error)

LoadFromBytes loads the key store from the bytes data.

func LoadJksFromReader

func LoadJksFromReader(reader io.Reader, password string) (*JKS, error)

LoadJksFromReader loads the key store from the specified file.

func NewJKS added in v1.0.1036

func NewJKS() *JKS

构造函数

func (*JKS) AddEncodedPrivateKey added in v1.0.1036

func (this *JKS) AddEncodedPrivateKey(
	alias string,
	encodedKey []byte,
	certChain [][]byte,
) error

添加私钥

func (*JKS) AddPrivateKey added in v1.0.1036

func (this *JKS) AddPrivateKey(
	alias string,
	privateKey crypto.PrivateKey,
	password string,
	certChain [][]byte,
) error

添加私钥

func (*JKS) AddTrustedCert added in v1.0.1036

func (this *JKS) AddTrustedCert(
	alias string,
	cert []byte,
) error

添加密钥

func (*JKS) GetCert added in v1.0.1036

func (this *JKS) GetCert(alias string) (*x509.Certificate, error)

GetCert

func (*JKS) GetCertBytes added in v1.0.1036

func (this *JKS) GetCertBytes(alias string) ([]byte, error)

GetCertBytes

func (*JKS) GetCertChain added in v1.0.1036

func (this *JKS) GetCertChain(alias string) ([]*x509.Certificate, error)

GetCertChain

func (*JKS) GetCertChainBytes added in v1.0.1036

func (this *JKS) GetCertChainBytes(alias string) ([][]byte, error)

GetCertChainBytes

func (*JKS) GetCreateDate added in v1.0.1036

func (this *JKS) GetCreateDate(alias string) (time.Time, error)

GetCreateDate

func (*JKS) GetEncodedKey added in v1.0.1036

func (this *JKS) GetEncodedKey(alias string) ([]byte, error)

GetEncodedKey

func (*JKS) GetPrivateKey added in v1.0.1036

func (this *JKS) GetPrivateKey(alias string, password string) (crypto.PrivateKey, error)

GetPrivateKey

func (*JKS) ListCerts added in v1.0.1036

func (this *JKS) ListCerts() []string

ListCerts

func (*JKS) ListPrivateKeys added in v1.0.1036

func (this *JKS) ListPrivateKeys() []string

ListPrivateKeys

func (*JKS) Marshal added in v1.0.1036

func (this *JKS) Marshal(password string) ([]byte, error)

func (*JKS) Parse added in v1.0.1036

func (this *JKS) Parse(r io.Reader, password string) error

解析

func (*JKS) String added in v1.0.1036

func (this *JKS) String() string

type Key

type Key interface {
	// 包装 PKCS8 证书
	MarshalPKCS8PrivateKey(privateKey crypto.PrivateKey) (pkData []byte, err error)

	// 解析 PKCS8 证书
	ParsePKCS8PrivateKey(pkData []byte) (crypto.PrivateKey, error)
}

Key 接口

type KeyDSA

type KeyDSA struct{}

DSA

func (KeyDSA) MarshalPKCS8PrivateKey

func (this KeyDSA) MarshalPKCS8PrivateKey(privateKey crypto.PrivateKey) ([]byte, error)

包装

func (KeyDSA) ParsePKCS8PrivateKey

func (this KeyDSA) ParsePKCS8PrivateKey(pkData []byte) (crypto.PrivateKey, error)

解析

type KeyEcdsa

type KeyEcdsa struct{}

Ecdsa

func (KeyEcdsa) MarshalPKCS8PrivateKey

func (this KeyEcdsa) MarshalPKCS8PrivateKey(privateKey crypto.PrivateKey) ([]byte, error)

包装

func (KeyEcdsa) ParsePKCS8PrivateKey

func (this KeyEcdsa) ParsePKCS8PrivateKey(pkData []byte) (crypto.PrivateKey, error)

解析

type KeyEdDSA

type KeyEdDSA struct{}

EdDSA

func (KeyEdDSA) MarshalPKCS8PrivateKey

func (this KeyEdDSA) MarshalPKCS8PrivateKey(privateKey crypto.PrivateKey) ([]byte, error)

包装

func (KeyEdDSA) ParsePKCS8PrivateKey

func (this KeyEdDSA) ParsePKCS8PrivateKey(pkData []byte) (crypto.PrivateKey, error)

解析

type KeyRsa

type KeyRsa struct{}

rsa

func (KeyRsa) MarshalPKCS8PrivateKey

func (this KeyRsa) MarshalPKCS8PrivateKey(privateKey crypto.PrivateKey) ([]byte, error)

包装

func (KeyRsa) ParsePKCS8PrivateKey

func (this KeyRsa) ParsePKCS8PrivateKey(pkData []byte) (crypto.PrivateKey, error)

解析

type KeySM2

type KeySM2 struct{}

SM2

func (KeySM2) MarshalPKCS8PrivateKey

func (this KeySM2) MarshalPKCS8PrivateKey(privateKey crypto.PrivateKey) ([]byte, error)

包装

func (KeySM2) ParsePKCS8PrivateKey

func (this KeySM2) ParsePKCS8PrivateKey(pkData []byte) (crypto.PrivateKey, error)

解析

Jump to

Keyboard shortcuts

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