pkcs8

package
v1.0.2010 Latest Latest
Warning

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

Go to latest
Published: May 6, 2023 License: Apache-2.0 Imports: 22 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AES128CBC = CipherCBC{
	// contains filtered or unexported fields
}

AES128CBC is the 128-bit key AES cipher in CBC mode.

View Source
var AES128CCM = CipherCCM{
	// contains filtered or unexported fields
}

AES128CCM is the 128-bit key AES cipher in CCM mode.

View Source
var AES128CCMb = CipherCCMb{
	// contains filtered or unexported fields
}

AES128CCMb is the 128-bit key AES cipher in CCM mode.

View Source
var AES128CFB = CipherCFB{
	// contains filtered or unexported fields
}

AES128CFB is the 128-bit key AES cipher in CFB mode.

View Source
var AES128ECB = CipherECB{
	// contains filtered or unexported fields
}

AES128ECB is the 128-bit key AES cipher in ECB mode.

View Source
var AES128GCM = CipherGCM{
	// contains filtered or unexported fields
}

AES128GCM is the 128-bit key AES cipher in GCM mode.

View Source
var AES128GCMb = CipherGCMb{
	// contains filtered or unexported fields
}

AES128GCMb is the 128-bit key AES cipher in GCM mode.

View Source
var AES128OFB = CipherOFB{
	// contains filtered or unexported fields
}

AES128OFB is the 128-bit key AES cipher in OFB mode.

View Source
var AES192CBC = CipherCBC{
	// contains filtered or unexported fields
}

AES192CBC is the 192-bit key AES cipher in CBC mode.

View Source
var AES192CCM = CipherCCM{
	// contains filtered or unexported fields
}

AES192CCM is the 192-bit key AES cipher in CCM mode.

View Source
var AES192CCMb = CipherCCMb{
	// contains filtered or unexported fields
}

AES192CCMb is the 192-bit key AES cipher in CCM mode.

View Source
var AES192CFB = CipherCFB{
	// contains filtered or unexported fields
}

AES192CFB is the 192-bit key AES cipher in CFB mode.

View Source
var AES192ECB = CipherECB{
	// contains filtered or unexported fields
}

AES192ECB is the 192-bit key AES cipher in ECB mode.

View Source
var AES192GCM = CipherGCM{
	// contains filtered or unexported fields
}

AES192GCM is the 192-bit key AES cipher in GCM mode.

View Source
var AES192GCMb = CipherGCMb{
	// contains filtered or unexported fields
}

AES192GCMb is the 192-bit key AES cipher in GCM mode.

View Source
var AES192OFB = CipherOFB{
	// contains filtered or unexported fields
}

AES192OFB is the 192-bit key AES cipher in OFB mode.

View Source
var AES256CBC = CipherCBC{
	// contains filtered or unexported fields
}

AES256CBC is the 256-bit key AES cipher in CBC mode.

View Source
var AES256CCM = CipherCCM{
	// contains filtered or unexported fields
}

AES256CCM is the 256-bit key AES cipher in CCM mode.

View Source
var AES256CCMb = CipherCCMb{
	// contains filtered or unexported fields
}

AES256CCMb is the 256-bit key AES cipher in CCM mode.

View Source
var AES256CFB = CipherCFB{
	// contains filtered or unexported fields
}

AES256CFB is the 256-bit key AES cipher in CFB mode.

View Source
var AES256ECB = CipherECB{
	// contains filtered or unexported fields
}

AES256ECB is the 256-bit key AES cipher in ECB mode.

View Source
var AES256GCM = CipherGCM{
	// contains filtered or unexported fields
}

AES256GCM is the 256-bit key AES cipher in GCM mode.

View Source
var AES256GCMb = CipherGCMb{
	// contains filtered or unexported fields
}

AES256GCMb is the 256-bit key AES cipher in GCM mode.

View Source
var AES256OFB = CipherOFB{
	// contains filtered or unexported fields
}

AES256OFB is the 256-bit key AES cipher in OFB mode.

View Source
var CipherMap = map[string]Cipher{
	"DESCBC":     DESCBC,
	"DESEDE3CBC": DESEDE3CBC,

	"AES128ECB":  AES128ECB,
	"AES128CBC":  AES128CBC,
	"AES128OFB":  AES128OFB,
	"AES128CFB":  AES128CFB,
	"AES128GCM":  AES128GCM,
	"AES128GCMb": AES128GCMb,
	"AES128CCM":  AES128CCM,
	"AES128CCMb": AES128CCMb,

	"AES192ECB":  AES192ECB,
	"AES192CBC":  AES192CBC,
	"AES192OFB":  AES192OFB,
	"AES192CFB":  AES192CFB,
	"AES192GCM":  AES192GCM,
	"AES192GCMb": AES192GCMb,
	"AES192CCM":  AES192CCM,
	"AES192CCMb": AES192CCMb,

	"AES256ECB":  AES256ECB,
	"AES256CBC":  AES256CBC,
	"AES256OFB":  AES256OFB,
	"AES256CFB":  AES256CFB,
	"AES256GCM":  AES256GCM,
	"AES256GCMb": AES256GCMb,
	"AES256CCM":  AES256CCM,
	"AES256CCMb": AES256CCMb,

	"SM4ECB":  SM4ECB,
	"SM4CBC":  SM4CBC,
	"SM4OFB":  SM4OFB,
	"SM4CFB":  SM4CFB,
	"SM4CFB1": SM4CFB1,
	"SM4CFB8": SM4CFB8,
	"SM4GCM":  SM4GCM,
	"SM4GCMb": SM4GCMb,
	"SM4CCM":  SM4CCM,
	"SM4CCMb": SM4CCMb,
}

Cipher 列表

View Source
var DESCBC = CipherCBC{
	// contains filtered or unexported fields
}

DESCBC is the 56-bit key 3DES cipher in CBC mode.

View Source
var DESEDE3CBC = CipherCBC{
	// contains filtered or unexported fields
}

TripleDESCBC is the 168-bit key 3DES cipher in CBC mode.

View Source
var (
	// 默认 hash
	DefaultHash = SHA1
)
View Source
var DefaultOpts = Opts{
	Cipher: AES256CBC,
	KDFOpts: PBKDF2Opts{
		SaltSize:       16,
		IterationCount: 10000,
	},
}

默认配置

View Source
var HashMap = map[string]Hash{
	"MD5":        MD5,
	"SHA1":       SHA1,
	"SHA224":     SHA224,
	"SHA256":     SHA256,
	"SHA384":     SHA384,
	"SHA512":     SHA512,
	"SHA512_224": SHA512_224,
	"SHA512_256": SHA512_256,
	"SM3":        SM3,
}

hash 列表

View Source
var SM4CBC = CipherCBC{
	// contains filtered or unexported fields
}

SM4CBC is the 128-bit key SM4 cipher in CBC mode.

View Source
var SM4CCM = CipherCCM{
	// contains filtered or unexported fields
}

SM4CCM is the 128-bit key SM4 cipher in CCM mode.

View Source
var SM4CCMb = CipherCCMb{
	// contains filtered or unexported fields
}

SM4CCMb is the 128-bit key SM4 cipher in CCM mode.

View Source
var SM4CFB = CipherCFB{
	// contains filtered or unexported fields
}

SM4CFB is the 128-bit key SM4 cipher in CFB mode.

View Source
var SM4CFB1 = CipherCFB1{
	// contains filtered or unexported fields
}

SM4CFB1 is the 128-bit key SM4 cipher in CFB mode.

View Source
var SM4CFB8 = CipherCFB8{
	// contains filtered or unexported fields
}

SM4CFB8 is the 128-bit key SM4 cipher in CFB mode.

View Source
var SM4ECB = CipherECB{
	// contains filtered or unexported fields
}

SM4ECB is the 128-bit key SM4 cipher in ECB mode.

View Source
var SM4GCM = CipherGCM{
	// contains filtered or unexported fields
}

SM4GCM is the 128-bit key SM4 cipher in GCM mode.

View Source
var SM4GCMb = CipherGCMb{
	// contains filtered or unexported fields
}

SM4GCMb is the 128-bit key SM4 cipher in GCM mode.

View Source
var SM4OFB = CipherOFB{
	// contains filtered or unexported fields
}

SM4OFB is the 128-bit key SM4 cipher in OFB mode.

Functions

func AddCipher added in v1.0.1018

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

添加加密

func AddKDF added in v1.0.1018

func AddKDF(oid asn1.ObjectIdentifier, params func() KDFParameters)

添加 kdf 方式

func DecryptPEMBlock

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

解出 PEM 块

func DecryptPKCS8PrivateKey

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

解出 PKCS8 密钥

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 {
	// oid
	OID() asn1.ObjectIdentifier

	// 值大小
	KeySize() int

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

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

加密接口

func GetCipherFromName added in v1.0.1020

func GetCipherFromName(name string) Cipher

获取 Cipher 类型

type CipherCBC added in v1.0.1020

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

cbc 模式加密

func (CipherCBC) Decrypt added in v1.0.1020

func (this CipherCBC) Decrypt(key, params, ciphertext []byte) ([]byte, error)

解密

func (CipherCBC) Encrypt added in v1.0.1020

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

加密

func (CipherCBC) KeySize added in v1.0.1020

func (this CipherCBC) KeySize() int

值大小

func (CipherCBC) OID added in v1.0.1020

func (this CipherCBC) OID() asn1.ObjectIdentifier

oid

type CipherCCM added in v1.0.1021

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

ccm 模式加密

func (CipherCCM) Decrypt added in v1.0.1021

func (this CipherCCM) Decrypt(key, param, ciphertext []byte) ([]byte, error)

解密

func (CipherCCM) Encrypt added in v1.0.1021

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

加密

func (CipherCCM) KeySize added in v1.0.1021

func (this CipherCCM) KeySize() int

值大小

func (CipherCCM) OID added in v1.0.1021

func (this CipherCCM) OID() asn1.ObjectIdentifier

oid

type CipherCCMb added in v1.0.1025

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

ccm 模式加密

func (CipherCCMb) Decrypt added in v1.0.1025

func (this CipherCCMb) Decrypt(key, param, ciphertext []byte) ([]byte, error)

解密

func (CipherCCMb) Encrypt added in v1.0.1025

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

加密

func (CipherCCMb) KeySize added in v1.0.1025

func (this CipherCCMb) KeySize() int

值大小

func (CipherCCMb) OID added in v1.0.1025

func (this CipherCCMb) OID() asn1.ObjectIdentifier

oid

type CipherCFB added in v1.0.1021

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

CFB 模式加密

func (CipherCFB) Decrypt added in v1.0.1021

func (this CipherCFB) Decrypt(key, params, ciphertext []byte) ([]byte, error)

解密

func (CipherCFB) Encrypt added in v1.0.1021

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

加密

func (CipherCFB) KeySize added in v1.0.1021

func (this CipherCFB) KeySize() int

值大小

func (CipherCFB) OID added in v1.0.1021

func (this CipherCFB) OID() asn1.ObjectIdentifier

oid

type CipherCFB1 added in v1.0.2006

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

CFB1 模式加密

func (CipherCFB1) Decrypt added in v1.0.2006

func (this CipherCFB1) Decrypt(key, params, ciphertext []byte) ([]byte, error)

解密

func (CipherCFB1) Encrypt added in v1.0.2006

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

加密

func (CipherCFB1) KeySize added in v1.0.2006

func (this CipherCFB1) KeySize() int

值大小

func (CipherCFB1) OID added in v1.0.2006

func (this CipherCFB1) OID() asn1.ObjectIdentifier

oid

type CipherCFB8 added in v1.0.1021

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

CFB8 模式加密

func (CipherCFB8) Decrypt added in v1.0.1021

func (this CipherCFB8) Decrypt(key, params, ciphertext []byte) ([]byte, error)

解密

func (CipherCFB8) Encrypt added in v1.0.1021

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

加密

func (CipherCFB8) KeySize added in v1.0.1021

func (this CipherCFB8) KeySize() int

值大小

func (CipherCFB8) OID added in v1.0.1021

func (this CipherCFB8) OID() asn1.ObjectIdentifier

oid

type CipherECB added in v1.0.1021

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

ecb 模式加密

func (CipherECB) Decrypt added in v1.0.1021

func (this CipherECB) Decrypt(key, params, ciphertext []byte) ([]byte, error)

解密

func (CipherECB) Encrypt added in v1.0.1021

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

加密

func (CipherECB) KeySize added in v1.0.1021

func (this CipherECB) KeySize() int

值大小

func (CipherECB) OID added in v1.0.1021

func (this CipherECB) OID() asn1.ObjectIdentifier

oid

type CipherGCM added in v1.0.1020

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

gcm 模式加密

func (CipherGCM) Decrypt added in v1.0.1020

func (this CipherGCM) Decrypt(key, param, ciphertext []byte) ([]byte, error)

解密

func (CipherGCM) Encrypt added in v1.0.1020

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

加密

func (CipherGCM) KeySize added in v1.0.1020

func (this CipherGCM) KeySize() int

值大小

func (CipherGCM) OID added in v1.0.1020

func (this CipherGCM) OID() asn1.ObjectIdentifier

oid

type CipherGCMb added in v1.0.1025

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

gcm 模式加密

func (CipherGCMb) Decrypt added in v1.0.1025

func (this CipherGCMb) Decrypt(key, param, ciphertext []byte) ([]byte, error)

解密

func (CipherGCMb) Encrypt added in v1.0.1025

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

加密

func (CipherGCMb) KeySize added in v1.0.1025

func (this CipherGCMb) KeySize() int

值大小

func (CipherGCMb) OID added in v1.0.1025

func (this CipherGCMb) OID() asn1.ObjectIdentifier

oid

type CipherOFB added in v1.0.1021

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

OFB 模式加密

func (CipherOFB) Decrypt added in v1.0.1021

func (this CipherOFB) Decrypt(key, params, ciphertext []byte) ([]byte, error)

解密

func (CipherOFB) Encrypt added in v1.0.1021

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

加密

func (CipherOFB) KeySize added in v1.0.1021

func (this CipherOFB) KeySize() int

值大小

func (CipherOFB) OID added in v1.0.1021

func (this CipherOFB) OID() asn1.ObjectIdentifier

oid

type Hash added in v1.0.1020

type Hash uint

pkcs8 可使用的 hash 方式

const (
	MD5 Hash = 1 + iota
	SHA1
	SHA224
	SHA256
	SHA384
	SHA512
	SHA512_224
	SHA512_256
	SM3
)

func GetHashFromName added in v1.0.1020

func GetHashFromName(name string) Hash

获取 hash 类型

type KDFOpts added in v1.0.1018

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

	// 生成密钥
	DeriveKey(password, salt []byte, size int) (key []byte, params KDFParameters, err error)

	// 随机数大小
	GetSaltSize() int
}

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
}

配置

func ParseOpts added in v1.0.1020

func ParseOpts(opts ...any) (Opts, error)

解析配置

type PBKDF2Opts added in v1.0.1018

type PBKDF2Opts struct {
	SaltSize       int
	IterationCount int
	HMACHash       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 PBKDF2OptsWithKeyLength added in v1.0.1033

type PBKDF2OptsWithKeyLength struct {
	SaltSize       int
	IterationCount int
	HMACHash       Hash
}

PBKDF2 配置,带KeyLength

func (PBKDF2OptsWithKeyLength) DeriveKey added in v1.0.1033

func (this PBKDF2OptsWithKeyLength) DeriveKey(password, salt []byte, size int) ([]byte, KDFParameters, error)

func (PBKDF2OptsWithKeyLength) GetSaltSize added in v1.0.1033

func (this PBKDF2OptsWithKeyLength) GetSaltSize() int

func (PBKDF2OptsWithKeyLength) OID added in v1.0.1033

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