crypto

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: Apache-2.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package crypto encrypts vendor LLM keys at rest with AES-256-GCM.

The keyring is parsed from KTMS_ENCRYPTION_KEYS ("1:<base64 32B>,2:..."). Every ciphertext records the key version that sealed it, so rotation is: add a higher version to the env, redeploy, re-encrypt all rows, drop the old version. Direct GCM rather than envelope encryption — this guards a few dozen rows, and a KMS round trip per read would buy nothing.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoKeys         = errors.New("crypto: no encryption keys configured")
	ErrUnknownVersion = errors.New("crypto: unknown key version")
)

Functions

func EncodeVersioned

func EncodeVersioned(blob []byte, version int) string

EncodeVersioned encodes a version and ciphertext blob as "v:<base64>".

func Fingerprint added in v1.2.0

func Fingerprint(plain string) string

Fingerprint names a credential without revealing it: the first 8 bytes of its SHA-256 in hex. Clients compute the same to tell whether a stored vendor key equals the one they hold, since the key itself is never returned.

Types

type Keyring

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

Keyring holds every key version the service can decrypt with, plus the active version used for new writes.

func ParseKeyring

func ParseKeyring(spec string) (*Keyring, error)

ParseKeyring reads "version:base64key[,version:base64key]". The highest version becomes active. Versions must be positive and keys exactly 32 bytes.

func (*Keyring) ActiveVersion

func (k *Keyring) ActiveVersion() int

ActiveVersion is the key version Encrypt seals with.

func (*Keyring) DecodeVersioned

func (k *Keyring) DecodeVersioned(encoded string) (string, error)

DecodeVersioned decodes an encoded string and decrypts it with the keyring.

func (*Keyring) Decrypt

func (k *Keyring) Decrypt(blob []byte, version int) (string, error)

Decrypt opens a nonce||ciphertext blob sealed with the given key version.

func (*Keyring) Encrypt

func (k *Keyring) Encrypt(plaintext string) ([]byte, int, error)

Encrypt seals plaintext with the active key. The returned blob is nonce||ciphertext and is stored as-is alongside the returned version.

func (*Keyring) Versions

func (k *Keyring) Versions() []int

Versions lists every version the keyring can decrypt, unordered.

Jump to

Keyboard shortcuts

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