local

package
v1.0.13 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package local provides an in-memory AES-256-GCM encryption provider for testing. It stores master keys in memory and supports key revocation for crypto-shredding simulation.

This provider should NOT be used in production. Use the kms or vault providers instead.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Provider) error

Option configures a local Provider.

func WithKey

func WithKey(keyID string, key []byte) Option

WithKey pre-loads a master key into the provider. The key must be exactly 32 bytes (AES-256).

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

Provider is an in-memory AES-256-GCM encryption provider for testing. Keys are stored in memory and never persisted.

func New

func New(opts ...Option) (*Provider, error)

New creates a new local encryption provider.

func (*Provider) AddKey

func (p *Provider) AddKey(keyID string, key []byte) error

AddKey adds a master key to the provider. The key must be exactly 32 bytes (AES-256).

func (*Provider) Close

func (p *Provider) Close() error

Close releases all key material.

func (*Provider) Decrypt

func (p *Provider) Decrypt(_ context.Context, keyID string, ciphertext []byte) ([]byte, error)

Decrypt decrypts ciphertext using AES-256-GCM with the specified master key.

func (*Provider) DecryptDataKey

func (p *Provider) DecryptDataKey(_ context.Context, keyID string, encryptedKey []byte) ([]byte, error)

DecryptDataKey decrypts a previously encrypted DEK using the master key.

func (*Provider) Encrypt

func (p *Provider) Encrypt(_ context.Context, keyID string, plaintext []byte) ([]byte, error)

Encrypt encrypts plaintext using AES-256-GCM with the specified master key.

func (*Provider) GenerateDataKey

func (p *Provider) GenerateDataKey(_ context.Context, keyID string) (*encryption.DataKey, error)

GenerateDataKey creates a new random 32-byte DEK and encrypts it with the master key.

func (*Provider) RevokeKey

func (p *Provider) RevokeKey(keyID string) error

RevokeKey marks a key as revoked and removes the key material. This simulates crypto-shredding: once revoked, data encrypted with this key can never be decrypted.

Jump to

Keyboard shortcuts

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