crypto

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package crypto provides AES-256-GCM encryption for credential storage.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func VaultExists

func VaultExists(cfg *config.Config) bool

VaultExists reports whether a vault key is already configured (env var set or key file exists on disk). It performs a read-only passive check and does NOT create files or initialize the vault.

Types

type Vault

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

Vault provides AES-256-GCM encryption using a single master key.

func NewVault

func NewVault(cfg *config.Config) (*Vault, error)

NewVault creates a Vault by loading or generating the encryption key. Key loading priority: 1. cfg.EncryptionKey (hex-decoded from ENGRAM_ENCRYPTION_KEY env var) 2. cfg.EncryptionKeyFile (read file from ENGRAM_ENCRYPTION_KEY_FILE env var) 3. Auto-generate: save to DataDir()/vault.key, log warning

func (*Vault) Decrypt

func (v *Vault) Decrypt(ciphertext []byte) (string, error)

Decrypt decrypts ciphertext produced by Encrypt. Expected format: nonce (12B) || ciphertext || GCM tag (16B).

func (*Vault) Encrypt

func (v *Vault) Encrypt(plaintext string) ([]byte, error)

Encrypt encrypts plaintext using AES-256-GCM. Returns nonce (12B) || ciphertext || GCM tag as a single byte slice.

func (*Vault) Fingerprint

func (v *Vault) Fingerprint() string

Fingerprint returns the first 16 hex chars of SHA-256(key).

func (*Vault) KeySource

func (v *Vault) KeySource() string

KeySource returns how the encryption key was loaded: "env", "file", or "auto_generated".

func (*Vault) MatchesFingerprint

func (v *Vault) MatchesFingerprint(fp string) bool

MatchesFingerprint reports whether fp matches this vault's key fingerprint. Uses constant-time comparison to avoid timing side-channels on key-derived material.

Jump to

Keyboard shortcuts

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