Documentation
¶
Overview ¶
Package crypto implements decrypt-only support for the field-level encrypted config values produced by the control plane at export time (see docs/zh_cn/sys_design/config_file_field_encryption.md). Key material is distributed via a shared keyring file; BFE never encrypts.
Index ¶
Constants ¶
const Marker = "enc$v1$"
Marker is the envelope prefix marking a field value as ciphertext:
enc$v1$<base64( keyID(1B) | nonce(12B) | AES-256-GCM(plaintext)+tag(16B) )>
Values without the marker are legacy plaintext and pass through unchanged.
Variables ¶
var ErrNoKeyring = errors.New("crypto: keyring not configured (Security.KeyFile)")
ErrNoKeyring is returned when a marker-prefixed value is decrypted without a keyring (Security.KeyFile not configured).
Functions ¶
func Decrypt ¶
Decrypt decrypts a single enc$v1$ envelope with the keyring. The key is selected by the keyID carried in the envelope itself, so ciphertexts encrypted with different keyIDs coexist naturally during rotation.
Error messages deliberately contain only the keyID and envelope length — never ciphertext or plaintext material.
Types ¶
type Keyring ¶
type Keyring struct {
// contains filtered or unexported fields
}
Keyring holds all in-service file-encryption keys, keyed by keyID. Multiple keyIDs coexist during rotation: decryption selects the key by the keyID embedded in each envelope, so old and new ciphertexts are both readable until the old keyID is retired.
func LoadKeyringFile ¶
LoadKeyringFile parses the shared TOML keyring file format (same file is used by the control plane to encrypt):
ActiveKeyID = 2 [Keys] 1 = "<base64 of 32-byte key>" # old key: decrypt legacy ciphertext 2 = "<base64 of 32-byte key>" # current key
ActiveKeyID is optional on the BFE (decrypt-only) side. Parsing is strict and fail-closed: malformed lines, duplicate keyIDs and bad key material are all errors.
func (*Keyring) ActiveKeyID ¶
ActiveKeyID returns the keyID marked active in the keyring file (informational on the BFE decrypt-only side).