pkcs8

package
v1.0.1019 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2022 License: Apache-2.0 Imports: 18 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AES128CBC = CipherBlock{
	// contains filtered or unexported fields
}
View Source
var AES192CBC = CipherBlock{
	// contains filtered or unexported fields
}
View Source
var AES256CBC = CipherBlock{
	// contains filtered or unexported fields
}
View Source
var DESCBC = CipherBlock{
	// contains filtered or unexported fields
}
View Source
var DESEDE3CBC = CipherBlock{
	// contains filtered or unexported fields
}
View Source
var DefaultOpts = Opts{
	Cipher: AES256CBC,
	KDFOpts: PBKDF2Opts{
		SaltSize:       16,
		IterationCount: 10000,
		HMACHash:       crypto.SHA256,
	},
}

默认配置

Functions

func AddCipher added in v1.0.1018

func AddCipher(oid asn1.ObjectIdentifier, cipher Cipher)

添加加密

func AddKDF added in v1.0.1018

func AddKDF(oid asn1.ObjectIdentifier, params KDFParameters)

添加 kdf 方式

func DecryptPEMBlock

func DecryptPEMBlock(block *pem.Block, password []byte) ([]byte, error)

解出 PEM 块

func DecryptPKCS8PrivateKey

func DecryptPKCS8PrivateKey(data, password []byte) ([]byte, error)

解出 PKCS8 密钥 加密方式: AES-128-CBC | AES-192-CBC | AES-256-CBC | DES | 3DES

func EncryptPKCS8PrivateKey

func EncryptPKCS8PrivateKey(
	rand io.Reader,
	blockType string,
	data []byte,
	password []byte,
	opts ...Opts,
) (*pem.Block, error)

加密 PKCS8

Types

type Cipher added in v1.0.1018

type Cipher interface {
	BlockSize() int
	KeySize() int
	Encrypt(key, iv, plaintext []byte) ([]byte, error)
	Decrypt(key, iv, ciphertext []byte) ([]byte, error)
	OID() asn1.ObjectIdentifier
}

加密接口

type CipherBlock added in v1.0.1018

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

加密

func (CipherBlock) BlockSize added in v1.0.1018

func (this CipherBlock) BlockSize() int

func (CipherBlock) Decrypt added in v1.0.1018

func (this CipherBlock) Decrypt(key, iv, ciphertext []byte) ([]byte, error)

解密

func (CipherBlock) Encrypt added in v1.0.1018

func (this CipherBlock) Encrypt(key, iv, plaintext []byte) ([]byte, error)

加密

func (CipherBlock) KeySize added in v1.0.1018

func (this CipherBlock) KeySize() int

func (CipherBlock) OID added in v1.0.1018

func (this CipherBlock) OID() asn1.ObjectIdentifier

type KDFOpts added in v1.0.1018

type KDFOpts interface {
	DeriveKey(password, salt []byte, size int) (key []byte, params KDFParameters, err error)
	GetSaltSize() int
	OID() asn1.ObjectIdentifier
}

KDF 设置接口

type KDFParameters added in v1.0.1018

type KDFParameters interface {
	DeriveKey(password []byte, size int) (key []byte, err error)
}

数据接口

type Opts

type Opts struct {
	Cipher  Cipher
	KDFOpts KDFOpts
}

配置

type PBKDF2Opts added in v1.0.1018

type PBKDF2Opts struct {
	SaltSize       int
	IterationCount int
	HMACHash       crypto.Hash
}

PBKDF2 配置

func (PBKDF2Opts) DeriveKey added in v1.0.1018

func (this PBKDF2Opts) DeriveKey(password, salt []byte, size int) (key []byte, params KDFParameters, err error)

func (PBKDF2Opts) GetSaltSize added in v1.0.1018

func (this PBKDF2Opts) GetSaltSize() int

func (PBKDF2Opts) OID added in v1.0.1018

func (this PBKDF2Opts) OID() asn1.ObjectIdentifier

type ScryptOpts added in v1.0.1018

type ScryptOpts struct {
	SaltSize                 int
	CostParameter            int
	BlockSize                int
	ParallelizationParameter int
}

ScryptOpts 设置

func (ScryptOpts) DeriveKey added in v1.0.1018

func (this ScryptOpts) DeriveKey(password, salt []byte, size int) (key []byte, params KDFParameters, err error)

func (ScryptOpts) GetSaltSize added in v1.0.1018

func (this ScryptOpts) GetSaltSize() int

func (ScryptOpts) OID added in v1.0.1018

func (this ScryptOpts) OID() asn1.ObjectIdentifier

Jump to

Keyboard shortcuts

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