Documentation
¶
Overview ¶
Package envelope implements KMS-native envelope encryption using a two-tier key hierarchy: Key Encryption Keys (KEKs) protect per-scope Data Encryption Keys (DEKs), and DEKs protect application data via local AEAD.
Index ¶
- type Envelope
- func (e *Envelope) ActiveKEKID() string
- func (e *Envelope) Decrypt(ctx context.Context, key *encryption.EncryptedKey, ciphertext, aad []byte) ([]byte, error)
- func (e *Envelope) DecryptString(ctx context.Context, key *encryption.EncryptedKey, ciphertext string, ...) (string, error)
- func (e *Envelope) Encrypt(ctx context.Context, key *encryption.EncryptedKey, plaintext, aad []byte) ([]byte, error)
- func (e *Envelope) EncryptString(ctx context.Context, key *encryption.EncryptedKey, plaintext string, ...) (string, error)
- func (e *Envelope) GenerateDEK() ([]byte, error)
- func (e *Envelope) OpenSession(ctx context.Context, key *encryption.EncryptedKey) (*Session, error)
- func (e *Envelope) RewrapDEK(ctx context.Context, key *encryption.EncryptedKey, targetKEKID string) ([]byte, error)
- func (e *Envelope) UnwrapDEK(ctx context.Context, key *encryption.EncryptedKey) ([]byte, error)
- func (e *Envelope) WrapDEK(ctx context.Context, scope encryption.KeyScope, dek []byte) (kekID string, encryptedDEK []byte, err error)
- type Session
- func (s *Session) Close()
- func (s *Session) Decrypt(ciphertext, aad []byte) ([]byte, error)
- func (s *Session) DecryptString(ciphertext string, aad []byte) (string, error)
- func (s *Session) Encrypt(plaintext, aad []byte) ([]byte, error)
- func (s *Session) EncryptString(plaintext string, aad []byte) (string, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Envelope ¶ added in v0.0.5
type Envelope struct {
// contains filtered or unexported fields
}
Envelope coordinates DEK generation, KEK-based wrapping/unwrapping/rewrapping with mandatory KeyScope AAD binding, and local AEAD data encryption/decryption. It is safe for concurrent use.
func New ¶ added in v0.0.5
New returns an Envelope wired to the given KEK keyring and symmetric data cipher. It panics if keyring or c is nil.
func (*Envelope) ActiveKEKID ¶ added in v0.0.6
ActiveKEKID returns the active KEK identifier from the keyring.
func (*Envelope) Decrypt ¶ added in v0.0.5
func (e *Envelope) Decrypt(ctx context.Context, key *encryption.EncryptedKey, ciphertext, aad []byte) ([]byte, error)
Decrypt unwraps key, decrypts ciphertext verifying optional payload aad, and scrubs the plaintext DEK from memory before returning.
func (*Envelope) DecryptString ¶ added in v0.0.6
func (e *Envelope) DecryptString(ctx context.Context, key *encryption.EncryptedKey, ciphertext string, aad []byte) (string, error)
DecryptString unwraps key, decrypts base64-encoded ciphertext verifying optional payload aad, and returns the UTF-8 plaintext string.
func (*Envelope) Encrypt ¶ added in v0.0.5
func (e *Envelope) Encrypt(ctx context.Context, key *encryption.EncryptedKey, plaintext, aad []byte) ([]byte, error)
Encrypt unwraps key, encrypts plaintext with optional payload aad, and scrubs the plaintext DEK from memory before returning.
func (*Envelope) EncryptString ¶ added in v0.0.6
func (e *Envelope) EncryptString(ctx context.Context, key *encryption.EncryptedKey, plaintext string, aad []byte) (string, error)
EncryptString unwraps key, encrypts a UTF-8 plaintext string with optional payload aad, and returns base64-encoded ciphertext.
func (*Envelope) GenerateDEK ¶ added in v0.0.5
GenerateDEK generates a new cryptographically secure random DEK matching the data cipher's key size. The caller is responsible for scrubbing memory with encryption.ZeroBytes(dek) when done.
func (*Envelope) OpenSession ¶ added in v0.0.6
func (e *Envelope) OpenSession(ctx context.Context, key *encryption.EncryptedKey) (*Session, error)
OpenSession unwraps key once and returns a reusable in-memory Session for high-throughput batch or stream encryption and decryption without repeated KMS calls. Callers must call defer session.Close() to scrub the plaintext DEK from memory.
func (*Envelope) RewrapDEK ¶ added in v0.0.6
func (e *Envelope) RewrapDEK(ctx context.Context, key *encryption.EncryptedKey, targetKEKID string) ([]byte, error)
RewrapDEK re-encrypts a stored DEK from key.KEKID to targetKEKID, verifying and preserving the canonical KeyScope AAD.
func (*Envelope) UnwrapDEK ¶ added in v0.0.5
func (e *Envelope) UnwrapDEK(ctx context.Context, key *encryption.EncryptedKey) ([]byte, error)
UnwrapDEK decrypts an EncryptedKey's DEK using the KEK identified by key.KEKID, verifying the canonical KeyScope AAD. The caller is responsible for scrubbing the returned slice with encryption.ZeroBytes(dek) when done.
type Session ¶ added in v0.0.6
type Session struct {
// contains filtered or unexported fields
}
Session holds an unwrapped DEK in memory for performing multiple local AEAD encrypt and decrypt operations without making repeated KMS unwrap calls.
A Session is safe for concurrent use and must be closed via Close when the unit of work finishes to scrub the plaintext DEK from memory.
func (*Session) Close ¶ added in v0.0.6
func (s *Session) Close()
Close scrubs the plaintext DEK from memory and marks the session as closed. Subsequent calls to Close are no-ops.
func (*Session) Decrypt ¶ added in v0.0.6
Decrypt decrypts ciphertext with the session's DEK and verifies optional aad.
func (*Session) DecryptString ¶ added in v0.0.6
DecryptString decodes base64-encoded ciphertext, decrypts it, and returns the UTF-8 plaintext string.