crypto

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2026 License: AGPL-3.0 Imports: 10 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

func KeyID added in v0.4.0

func KeyID(key []byte) string

KeyID returns a stable, non-secret identifier for a key. The truncated SHA-256 digest remains the same regardless of key-ring ordering.

Types

type Encryptor

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

Encryptor encrypts and decrypts data using AES-256-GCM with stable key IDs.

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) DecryptWithAAD added in v0.4.0

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

DecryptWithAAD decrypts 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) EncryptWithAAD added in v0.4.0

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

EncryptWithAAD encrypts plaintext into a key-ID envelope containing a nonce and authenticated ciphertext. The aad is authenticated but NOT encrypted; decryption only succeeds when DecryptWithAAD is given the identical aad. Used to bind ciphertext to a context so it cannot be decrypted under another one.

func (*Encryptor) NeedsRewrap added in v0.4.0

func (e *Encryptor) NeedsRewrap(encoded string) bool

NeedsRewrap reports whether encoded uses a non-current key. It validates only the envelope; Rewrap callers still authenticate it by decrypting before replacing persisted data.

Jump to

Keyboard shortcuts

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