Documentation
¶
Index ¶
- func DeriveAES256KeyFromPassword(password string, salt []byte) ([]byte, error)
- func DeriveAES256KeyFromPasswordBase64(password string, salt []byte) (string, error)
- func DeriveHMACKeyFromPassword(password string, salt []byte) ([]byte, error)
- func DeriveHMACKeyFromPasswordBase64(password string, salt []byte) (string, error)
- func GenerateSalt(saltLen int) ([]byte, error)
- func GenerateSaltBase64(saltLen int) (string, error)
- func HKDF(hashAlg HashAlgorithm, ikm []byte, salt []byte, info []byte, keyLen int) ([]byte, error)
- func HKDFBase64(hashAlg HashAlgorithm, ikm []byte, salt []byte, info []byte, keyLen int) (string, error)
- func HKDFString(hashAlg HashAlgorithm, ikm string, salt []byte, info []byte, keyLen int) ([]byte, error)
- func HKDFStringBase64(hashAlg HashAlgorithm, ikm string, salt []byte, info []byte, keyLen int) (string, error)
- func PBKDF2(password []byte, salt []byte, iterations int, keyLen int, ...) ([]byte, error)
- func PBKDF2Base64(password []byte, salt []byte, iterations int, keyLen int, ...) (string, error)
- func PBKDF2String(password string, salt []byte, iterations int, keyLen int, ...) ([]byte, error)
- func PBKDF2StringBase64(password string, salt []byte, iterations int, keyLen int, ...) (string, error)
- type HashAlgorithm
- type KDFManager
- func (m *KDFManager) DeriveFromKeyMaterial(ikm []byte, salt []byte, info []byte) ([]byte, error)
- func (m *KDFManager) DeriveFromKeyMaterialString(ikm string, salt []byte, info []byte) ([]byte, error)
- func (m *KDFManager) DeriveFromPassword(password []byte, salt []byte) ([]byte, error)
- func (m *KDFManager) DeriveFromPasswordString(password string, salt []byte) ([]byte, error)
- func (m *KDFManager) DeriveMultipleKeys(password []byte, salt []byte, keyCount int) ([][]byte, error)
- func (m *KDFManager) WithHashAlgorithm(hashAlg HashAlgorithm) *KDFManager
- func (m *KDFManager) WithIterations(iterations int) *KDFManager
- func (m *KDFManager) WithKeyLength(keyLen int) *KDFManager
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeriveAES256KeyFromPassword ¶
DeriveAES256KeyFromPassword 便捷函数:从密码派生AES-256密钥
func DeriveAES256KeyFromPasswordBase64 ¶
DeriveAES256KeyFromPasswordBase64 便捷函数:派生AES-256密钥并返回Base64编码
func DeriveHMACKeyFromPassword ¶
DeriveHMACKeyFromPassword 便捷函数:从密码派生HMAC密钥
func DeriveHMACKeyFromPasswordBase64 ¶
DeriveHMACKeyFromPasswordBase64 便捷函数:派生HMAC密钥并返回Base64编码
func GenerateSaltBase64 ¶
GenerateSaltBase64 生成随机盐值并返回Base64编码结果
func HKDFBase64 ¶
func HKDFBase64(hashAlg HashAlgorithm, ikm []byte, salt []byte, info []byte, keyLen int) (string, error)
HKDFBase64 使用HKDF算法派生密钥并返回Base64编码结果
func HKDFString ¶
func HKDFString(hashAlg HashAlgorithm, ikm string, salt []byte, info []byte, keyLen int) ([]byte, error)
HKDFString 使用HKDF算法从字符串输入密钥材料派生密钥
func HKDFStringBase64 ¶
func HKDFStringBase64(hashAlg HashAlgorithm, ikm string, salt []byte, info []byte, keyLen int) (string, error)
HKDFStringBase64 使用字符串输入密钥材料派生密钥并返回Base64编码结果
func PBKDF2 ¶
func PBKDF2(password []byte, salt []byte, iterations int, keyLen int, hashAlg HashAlgorithm) ([]byte, error)
PBKDF2 使用PBKDF2算法从密码派生密钥
func PBKDF2Base64 ¶
func PBKDF2Base64(password []byte, salt []byte, iterations int, keyLen int, hashAlg HashAlgorithm) (string, error)
PBKDF2Base64 使用PBKDF2算法派生密钥并返回Base64编码结果
func PBKDF2String ¶
func PBKDF2String(password string, salt []byte, iterations int, keyLen int, hashAlg HashAlgorithm) ([]byte, error)
PBKDF2String 使用PBKDF2算法从字符串密码派生密钥
func PBKDF2StringBase64 ¶
func PBKDF2StringBase64(password string, salt []byte, iterations int, keyLen int, hashAlg HashAlgorithm) (string, error)
PBKDF2StringBase64 使用字符串密码派生密钥并返回Base64编码结果
Types ¶
type HashAlgorithm ¶
type HashAlgorithm string
HashAlgorithm 哈希算法类型
const ( HashSHA256 HashAlgorithm = "sha256" HashSHA512 HashAlgorithm = "sha512" )
type KDFManager ¶
type KDFManager struct {
// contains filtered or unexported fields
}
KDFManager KDF管理器,提供便捷的密钥派生功能
func (*KDFManager) DeriveFromKeyMaterial ¶
DeriveFromKeyMaterial 从密钥材料派生密钥(使用HKDF)
func (*KDFManager) DeriveFromKeyMaterialString ¶
func (m *KDFManager) DeriveFromKeyMaterialString(ikm string, salt []byte, info []byte) ([]byte, error)
DeriveFromKeyMaterialString 从字符串密钥材料派生密钥
func (*KDFManager) DeriveFromPassword ¶
func (m *KDFManager) DeriveFromPassword(password []byte, salt []byte) ([]byte, error)
DeriveFromPassword 从密码派生密钥(使用PBKDF2)
func (*KDFManager) DeriveFromPasswordString ¶
func (m *KDFManager) DeriveFromPasswordString(password string, salt []byte) ([]byte, error)
DeriveFromPasswordString 从字符串密码派生密钥
func (*KDFManager) DeriveMultipleKeys ¶
func (m *KDFManager) DeriveMultipleKeys(password []byte, salt []byte, keyCount int) ([][]byte, error)
DeriveMultipleKeys 派生多个密钥(用于不同用途)
func (*KDFManager) WithHashAlgorithm ¶
func (m *KDFManager) WithHashAlgorithm(hashAlg HashAlgorithm) *KDFManager
WithHashAlgorithm 设置默认哈希算法
func (*KDFManager) WithIterations ¶
func (m *KDFManager) WithIterations(iterations int) *KDFManager
WithIterations 设置默认迭代次数
func (*KDFManager) WithKeyLength ¶
func (m *KDFManager) WithKeyLength(keyLen int) *KDFManager
WithKeyLength 设置默认密钥长度