crypto

package
v0.4.0-rc.13 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package crypto provides AES-256-GCM encryption with versioned keys for rotation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Encryptor

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

Encryptor encrypts and decrypts data using AES-256-GCM with versioned keys. The version byte prefix allows decryption with old keys during rotation.

func New

func New(currentKey []byte, oldKeys ...[]byte) *Encryptor

New creates an Encryptor. currentKey is the active encryption key (32 bytes for AES-256). oldKeys are previous keys that can still decrypt but won't be used for new encryptions. Panics if any key is not exactly 32 bytes.

func (*Encryptor) Decrypt

func (e *Encryptor) Decrypt(encoded string) (string, error)

Decrypt decodes a base64-encoded string and decrypts it using the key identified by the version byte prefix.

func (*Encryptor) DecryptWithAAD added in v0.4.0

func (e *Encryptor) DecryptWithAAD(encoded, aad string) (string, error)

DecryptWithAAD is Decrypt for ciphertext produced by EncryptWithAAD. It returns an error when aad doesn't match the value used at encryption time (the GCM auth tag fails to verify) — that mismatch is the binding guarantee.

func (*Encryptor) Encrypt

func (e *Encryptor) Encrypt(plaintext string) (string, error)

Encrypt encrypts plaintext and returns a base64-encoded string containing: version byte + nonce + ciphertext.

func (*Encryptor) EncryptWithAAD added in v0.4.0

func (e *Encryptor) EncryptWithAAD(plaintext, aad string) (string, error)

EncryptWithAAD is Encrypt with additional authenticated data folded into the GCM tag. The aad is authenticated but NOT encrypted; decryption only succeeds when DecryptWithAAD is given the identical aad. Used to bind a ciphertext to a context (e.g. an agent ID) so it can't be decrypted under a different context. aad="" is byte-identical to Encrypt (no binding).

Jump to

Keyboard shortcuts

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