vault

package
v1.1.15 Latest Latest
Warning

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

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

Documentation

Overview

Package vault provides a HashiCorp Vault Transit encryption provider for field-level encryption. It uses the Vault Transit engine for key management while generating DEKs locally for envelope encryption.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Provider)

Option configures a Vault Provider.

func WithVaultClient

func WithVaultClient(client VaultClient) Option

WithVaultClient sets the Vault Transit client.

type Provider

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

Provider implements encryption.Provider using HashiCorp Vault Transit.

func New

func New(opts ...Option) *Provider

New creates a new Vault Transit encryption provider.

func (*Provider) Close

func (p *Provider) Close() error

Close marks the provider as closed.

func (*Provider) Decrypt

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

Decrypt decrypts ciphertext using the Vault Transit key.

func (*Provider) DecryptDataKey

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

DecryptDataKey decrypts a previously encrypted DEK using Vault Transit.

func (*Provider) Encrypt

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

Encrypt encrypts plaintext using the Vault Transit key.

func (*Provider) GenerateDataKey

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

GenerateDataKey creates a new random 32-byte DEK and encrypts it via Vault Transit. Unlike KMS, Vault Transit doesn't have a native GenerateDataKey API, so we generate the DEK locally and encrypt it with Vault.

func (*Provider) IsRevoked added in v1.1.3

func (p *Provider) IsRevoked(keyID string) (bool, error)

IsRevoked reports whether keyID's Transit key has been deleted. It implements encryption.Revocable.

func (*Provider) RevokeKey added in v1.1.3

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

RevokeKey crypto-shreds keyID by deleting its Vault Transit key. It implements encryption.Revocable. It requires the injected client to implement VaultRevocationClient, otherwise it returns ErrRevocationUnsupported. It is idempotent: a key that no longer exists returns nil.

type VaultClient

type VaultClient interface {
	// Encrypt encrypts plaintext using the named Transit key.
	Encrypt(ctx context.Context, keyName string, plaintext []byte) (ciphertext []byte, err error)

	// Decrypt decrypts ciphertext using the named Transit key.
	Decrypt(ctx context.Context, keyName string, ciphertext []byte) (plaintext []byte, err error)
}

VaultClient defines the minimal interface for Vault Transit operations. Users inject their own implementation (e.g., wrapping the official Vault SDK).

type VaultRevocationClient added in v1.1.3

type VaultRevocationClient interface {
	// DeleteKey deletes the named Transit key (the key must allow deletion).
	DeleteKey(ctx context.Context, keyName string) error
	// KeyExists reports whether the named Transit key still exists.
	KeyExists(ctx context.Context, keyName string) (bool, error)
}

VaultRevocationClient is an OPTIONAL extension of VaultClient. When the injected client also implements it, the provider implements encryption.Revocable and supports crypto-shredding (GDPR erasure) by deleting the named Transit key so its ciphertext can never be decrypted again.

Jump to

Keyboard shortcuts

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