Documentation ¶
Index ¶
- Variables
- func AddCipher(oid asn1.ObjectIdentifier, cipher Cipher)
- func AddKDF(oid asn1.ObjectIdentifier, params KDFParameters)
- func DecryptPEMBlock(block *pem.Block, password []byte) ([]byte, error)
- func DecryptPKCS8PrivateKey(data, password []byte) ([]byte, error)
- func EncryptPKCS8PrivateKey(rand io.Reader, blockType string, data []byte, password []byte, opts ...Opts) (*pem.Block, error)
- type Cipher
- type CipherCBC
- type CipherGCM
- type Hash
- type KDFOpts
- type KDFParameters
- type Opts
- type PBKDF2Opts
- type ScryptOpts
Constants ¶
This section is empty.
Variables ¶
var AES128CBC = CipherCBC{ // contains filtered or unexported fields }
AES128CBC is the 128-bit key AES cipher in CBC mode.
var AES128GCM = CipherGCM{ // contains filtered or unexported fields }
AES128GCM is the 128-bit key AES cipher in GCM mode.
var AES192CBC = CipherCBC{ // contains filtered or unexported fields }
AES192CBC is the 192-bit key AES cipher in CBC mode.
var AES192GCM = CipherGCM{ // contains filtered or unexported fields }
AES192GCM is the 192-bit key AES cipher in GCM mode.
var AES256CBC = CipherCBC{ // contains filtered or unexported fields }
AES256CBC is the 256-bit key AES cipher in CBC mode.
var AES256GCM = CipherGCM{ // contains filtered or unexported fields }
AES256GCM is the 256-bit key AES cipher in GCM mode.
var CipherMap = map[string]Cipher{ "DESCBC": DESCBC, "DESEDE3CBC": DESEDE3CBC, "AES128CBC": AES128CBC, "AES192CBC": AES192CBC, "AES256CBC": AES256CBC, "AES128GCM": AES128GCM, "AES192GCM": AES192GCM, "AES256GCM": AES256GCM, "SM4CBC": SM4CBC, "SM4GCM": SM4GCM, }
Cipher 列表
var DESCBC = CipherCBC{ // contains filtered or unexported fields }
DESCBC is the 56-bit key 3DES cipher in CBC mode.
var DESEDE3CBC = CipherCBC{ // contains filtered or unexported fields }
TripleDESCBC is the 168-bit key 3DES cipher in CBC mode.
var DefaultOpts = Opts{ Cipher: AES256CBC, KDFOpts: PBKDF2Opts{ SaltSize: 16, IterationCount: 10000, HMACHash: SHA256, }, }
默认配置
var HashMap = map[string]Hash{ "MD4": MD4, "MD5": MD5, "SHA1": SHA1, "SHA224": SHA224, "SHA256": SHA256, "SHA384": SHA384, "SHA512": SHA512, "SHA512_224": SHA512_224, "SHA512_256": SHA512_256, "SM3": SM3, }
hash 列表
var SM4CBC = CipherCBC{ // contains filtered or unexported fields }
SM4CBC is the 128-bit key SM4 cipher in CBC mode.
var SM4GCM = CipherGCM{ // contains filtered or unexported fields }
SM4GCM is the 128-bit key SM4 cipher in GCM mode.
Functions ¶
func AddKDF ¶ added in v1.0.1018
func AddKDF(oid asn1.ObjectIdentifier, params KDFParameters)
添加 kdf 方式
func DecryptPEMBlock ¶
解出 PEM 块
func DecryptPKCS8PrivateKey ¶
解出 PKCS8 密钥 加密方式: AES-128-CBC | AES-192-CBC | AES-256-CBC | DES | 3DES
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) }
加密接口
type CipherCBC ¶ added in v1.0.1020
type CipherCBC struct {
// contains filtered or unexported fields
}
cbc 模式加密
type CipherGCM ¶ added in v1.0.1020
type CipherGCM struct {
// contains filtered or unexported fields
}
gcm 模式加密
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 PBKDF2Opts ¶ added in v1.0.1018
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