crypto

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package crypto encrypts provider API keys at rest with AES-256-GCM under a master key from the environment, so a database leak never yields usable secrets.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoKey = errors.New("crypto: master key not configured")

Functions

func GenerateKey

func GenerateKey() (string, error)

GenerateKey returns a fresh base64-encoded 32-byte key for first-run bootstrap.

Types

type SecretBox

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

SecretBox seals and opens secrets with one 32-byte key.

func LoadOrGenerate

func LoadOrGenerate(base64Key string) (box *SecretBox, generated string, err error)

LoadOrGenerate builds a SecretBox from base64Key. When the key is empty it generates an ephemeral one and returns it in generated (non-empty) so the caller can warn the operator to persist it — provider keys sealed with an ephemeral key are lost on restart. A malformed or wrong-length key is an error.

func New

func New(base64Key string) (*SecretBox, error)

New builds a SecretBox from a base64-encoded 32-byte key. An empty key returns ErrNoKey so callers can decide whether to bootstrap one.

func (*SecretBox) Decrypt

func (s *SecretBox) Decrypt(ciphertext []byte) (string, error)

Decrypt opens nonce-prefixed ciphertext produced by Encrypt.

func (*SecretBox) Encrypt

func (s *SecretBox) Encrypt(plaintext string) ([]byte, error)

Encrypt seals plaintext, returning nonce-prefixed ciphertext.

Jump to

Keyboard shortcuts

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