Documentation ¶
Index ¶
- Variables
- func AddKDF(oid asn1.ObjectIdentifier, params func() 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)
- func IsUseKeyLengthCipher(cipher Cipher) bool
- type Cipher
- type Hash
- type KDFOpts
- type KDFParameters
- type Opts
- type PBKDF2Opts
- type PBKDF2OptsWithKeyLength
- type ScryptOpts
Constants ¶
This section is empty.
Variables ¶
View Source
var ( AddCipher = pbes2.AddCipher GetCipher = pbes2.GetCipher // 帮助函数 GetCipherFromName = pbes2.GetCipherFromName CheckCipherFromName = pbes2.CheckCipherFromName )
View Source
var ( DESCBC = pbes2.DESCBC DESEDE3CBC = pbes2.DESEDE3CBC RC2CBC = pbes2.RC2CBC RC2_40CBC = pbes2.RC2_40CBC RC2_64CBC = pbes2.RC2_64CBC RC2_128CBC = pbes2.RC2_128CBC RC5CBC = pbes2.RC5CBC RC5_128CBC = pbes2.RC5_128CBC RC5_192CBC = pbes2.RC5_192CBC RC5_256CBC = pbes2.RC5_256CBC AES128ECB = pbes2.AES128ECB AES128CBC = pbes2.AES128CBC AES128OFB = pbes2.AES128OFB AES128CFB = pbes2.AES128CFB AES128GCM = pbes2.AES128GCM AES128CCM = pbes2.AES128CCM AES192ECB = pbes2.AES192ECB AES192CBC = pbes2.AES192CBC AES192OFB = pbes2.AES192OFB AES192CFB = pbes2.AES192CFB AES192GCM = pbes2.AES192GCM AES192CCM = pbes2.AES192CCM AES256ECB = pbes2.AES256ECB AES256CBC = pbes2.AES256CBC AES256OFB = pbes2.AES256OFB AES256CFB = pbes2.AES256CFB AES256GCM = pbes2.AES256GCM AES256CCM = pbes2.AES256CCM SM4ECB = pbes2.SM4ECB SM4CBC = pbes2.SM4CBC SM4OFB = pbes2.SM4OFB SM4CFB = pbes2.SM4CFB SM4CFB1 = pbes2.SM4CFB1 SM4CFB8 = pbes2.SM4CFB8 SM4GCM = pbes2.SM4GCM SM4CCM = pbes2.SM4CCM )
加密方式
View Source
var ( // 默认 hash DefaultHash = SHA1 )
View Source
var DefaultOpts = Opts{ Cipher: AES256CBC, KDFOpts: DefaultPBKDF2Opts, }
默认配置
View Source
var DefaultPBKDF2Opts = PBKDF2Opts{
SaltSize: 16,
IterationCount: 10000,
}
默认配置 PBKDF2
View Source
var DefaultPBKDF2OptsWithKeyLength = PBKDF2OptsWithKeyLength{
SaltSize: 16,
IterationCount: 10000,
}
默认配置 PBKDF2,带 key 长度
View Source
var DefaultScryptOpts = ScryptOpts{
SaltSize: 16,
CostParameter: 1 << 2,
BlockSize: 8,
ParallelizationParameter: 1,
}
默认配置 Scrypt
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 列表
Functions ¶
func AddKDF ¶ added in v1.0.1018
func AddKDF(oid asn1.ObjectIdentifier, params func() KDFParameters)
添加 kdf 方式
func DecryptPEMBlock ¶
解出 PEM 块
func DecryptPKCS8PrivateKey ¶
解出 PKCS8 密钥
func EncryptPKCS8PrivateKey ¶
func EncryptPKCS8PrivateKey( rand io.Reader, blockType string, data []byte, password []byte, opts ...Opts, ) (*pem.Block, error)
加密 PKCS8
func IsUseKeyLengthCipher ¶ added in v1.0.2028
需要设置 KeyLength 的 Cipher
Types ¶
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 PBKDF2OptsWithKeyLength ¶ added in v1.0.1033
PBKDF2 配置,带 key 长度
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
func (this PBKDF2OptsWithKeyLength) 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
Source Files ¶
Click to show internal directories.
Click to hide internal directories.