Documentation
¶
Overview ¶
Package credential 提供凭据(API Key、密钥等敏感串)的对称加密与加密存储能力。
底层复用 toolkit/crypto/aes 的 AES-GCM 认证加密(随机 nonce + 完整性校验), 在其上提供两层易用封装:
- Cipher:单串加解密;
- Store:命名凭据的"加密落库 / 取用解密"存储,敏感值在内存中始终以密文保存。
设计遵循 CLAUDE.md 基础设施复用原则:加密算法用 toolkit/crypto/aes,本包只做 面向凭据场景的语义封装(密钥校验、命名存储、脱敏展示)。
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrNotFound = fmt.Errorf("credential: 凭据不存在")
ErrNotFound 表示请求的命名凭据不存在。
Functions ¶
Types ¶
type Cipher ¶
type Cipher struct {
// contains filtered or unexported fields
}
Cipher 用 AES-GCM 对凭据做对称加解密。
GCM 为认证加密:密文被篡改或密钥不符时解密会失败,而非返回错误明文。
func NewCipher ¶
NewCipher 用给定密钥创建 Cipher。
key 长度必须为 16/24/32 字节,对应 AES-128/192/256。 可用 toolkit/crypto/aes.GenerateKey(32) 生成安全随机密钥。
Click to show internal directories.
Click to hide internal directories.