crypto

package
v0.2.8 Latest Latest
Warning

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

Go to latest
Published: May 5, 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) Encrypt

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

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

Jump to

Keyboard shortcuts

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