envelope

package
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 31, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package envelope implements pure in-memory envelope encryption using a two-tier key hierarchy: system keys (KEKs) protect data encryption keys (DEKs), and DEKs protect application data.

Index

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 performs in-memory envelope encrypt/decrypt and DEK wrapping/unwrapping. It is safe for concurrent use and has zero storage or database dependencies.

func New added in v0.0.5

func New(keyring systemkey.Keyring, c cipher.Cipher) *Envelope

New returns an Envelope wired to the given keyring and symmetric cipher.

func (*Envelope) ActiveKeyID added in v0.0.5

func (e *Envelope) ActiveKeyID() string

ActiveKeyID returns the active system key ID from the keyring.

func (*Envelope) Decrypt added in v0.0.5

func (e *Envelope) Decrypt(systemKeyID string, encryptedDEK []byte, ciphertext string) (string, error)

Decrypt unwraps the encrypted DEK using the specified system key, then decrypts the base64-encoded ciphertext using the DEK and returns the plaintext.

func (*Envelope) Encrypt added in v0.0.5

func (e *Envelope) Encrypt(systemKeyID string, encryptedDEK []byte, plaintext string) (string, error)

Encrypt unwraps the encrypted DEK using the specified system key, then encrypts the plaintext with the DEK and returns base64-encoded ciphertext.

func (*Envelope) GenerateDEK added in v0.0.5

func (e *Envelope) GenerateDEK() ([]byte, error)

GenerateDEK generates a new cryptographically secure random DEK matching the cipher's key size. The caller is responsible for scrubbing memory with encryption.ZeroBytes(dek) when done.

func (*Envelope) UnwrapDEK added in v0.0.5

func (e *Envelope) UnwrapDEK(systemKeyID string, encryptedDEK []byte) ([]byte, error)

UnwrapDEK decrypts an encrypted DEK using the specified system key and returns the raw plaintext DEK bytes. The caller is responsible for scrubbing memory with encryption.ZeroBytes(dek) when done.

func (*Envelope) WrapDEK added in v0.0.5

func (e *Envelope) WrapDEK(systemKeyID string, dek []byte) ([]byte, error)

WrapDEK encrypts a raw plaintext DEK using the specified system key.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL