crypto

package
v1.8.2 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 11 Imported by: 8

Documentation

Overview

Package crypto provides AES-256-GCM encryption for Vault secrets.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidKeySize = errors.New("crypto: key must be exactly 32 bytes for AES-256")

ErrInvalidKeySize is returned when the key is not exactly 32 bytes.

Functions

This section is empty.

Types

type EncryptionKeyProvider

type EncryptionKeyProvider interface {
	// GetKey returns the current encryption key.
	GetKey(ctx context.Context) ([]byte, error)

	// RotateKey generates and stores a new key, returning it.
	RotateKey(ctx context.Context) ([]byte, error)
}

EncryptionKeyProvider retrieves and rotates encryption keys.

type Encryptor

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

Encryptor provides AES-256-GCM encryption and decryption.

func NewEncryptor

func NewEncryptor(key []byte) (*Encryptor, error)

NewEncryptor creates an Encryptor from a 32-byte AES-256 key.

func (*Encryptor) Decrypt

func (e *Encryptor) Decrypt(ciphertext []byte) ([]byte, error)

Decrypt decrypts ciphertext produced by Encrypt. It expects the nonce prepended: nonce || ciphertext.

func (*Encryptor) Encrypt

func (e *Encryptor) Encrypt(plaintext []byte) ([]byte, error)

Encrypt encrypts plaintext using AES-256-GCM. The returned ciphertext has the random nonce prepended: nonce || ciphertext.

type EnvKeyProvider

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

EnvKeyProvider reads the encryption key from an environment variable. The key can be hex-encoded or base64-encoded (auto-detected).

func NewEnvKeyProvider

func NewEnvKeyProvider(envVar string) *EnvKeyProvider

NewEnvKeyProvider creates a provider that reads the key from the given env var.

func (*EnvKeyProvider) GetKey

func (p *EnvKeyProvider) GetKey(_ context.Context) ([]byte, error)

GetKey reads and decodes the encryption key from the environment variable.

func (*EnvKeyProvider) RotateKey

func (p *EnvKeyProvider) RotateKey(_ context.Context) ([]byte, error)

RotateKey is not supported by the environment provider.

type KeyStore

type KeyStore interface {
	// GetOrCreate retrieves the key for the given ID, creating one if it doesn't exist.
	GetOrCreate(ctx context.Context, id string) ([]byte, error)

	// Get retrieves the key for the given ID.
	Get(ctx context.Context, id string) ([]byte, error)

	// Delete removes the key for the given ID (crypto-shredding).
	Delete(ctx context.Context, id string) error
}

KeyStore manages per-entity encryption keys (for GDPR-style per-tenant key isolation).

Jump to

Keyboard shortcuts

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