Documentation
¶
Overview ¶
Package crypto provides AES-256-GCM encryption with versioned keys for rotation.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Encryptor ¶
type Encryptor struct {
// contains filtered or unexported fields
}
Encryptor encrypts and decrypts data using AES-256-GCM with versioned keys. The version byte prefix allows decryption with old keys during rotation.
func New ¶
New creates an Encryptor. currentKey is the active encryption key (32 bytes for AES-256). oldKeys are previous keys that can still decrypt but won't be used for new encryptions. Panics if any key is not exactly 32 bytes.
func (*Encryptor) Decrypt ¶
Decrypt decodes a base64-encoded string and decrypts it using the key identified by the version byte prefix.
func (*Encryptor) DecryptWithAAD ¶ added in v0.4.0
DecryptWithAAD is Decrypt for ciphertext produced by EncryptWithAAD. It returns an error when aad doesn't match the value used at encryption time (the GCM auth tag fails to verify) — that mismatch is the binding guarantee.
func (*Encryptor) Encrypt ¶
Encrypt encrypts plaintext and returns a base64-encoded string containing: version byte + nonce + ciphertext.
func (*Encryptor) EncryptWithAAD ¶ added in v0.4.0
EncryptWithAAD is Encrypt with additional authenticated data folded into the GCM tag. The aad is authenticated but NOT encrypted; decryption only succeeds when DecryptWithAAD is given the identical aad. Used to bind a ciphertext to a context (e.g. an agent ID) so it can't be decrypted under a different context. aad="" is byte-identical to Encrypt (no binding).