crypto

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: AGPL-3.0 Imports: 7 Imported by: 1 module, 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type KeyStore

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

KeyStore holds versioned encryption keys. The current key version is used for new encryptions; older versions are retained for decryption during key rotation.

func NewKeyStore

func NewKeyStore(keys map[int]string, currentVersion int) (*KeyStore, error)

NewKeyStore creates a KeyStore from a map of version → base64-encoded 32-byte keys. The currentVersion is used for all new encryptions.

func (*KeyStore) CurrentVersion

func (ks *KeyStore) CurrentVersion() int

CurrentVersion returns the key version used for new encryptions.

func (*KeyStore) Decrypt

func (ks *KeyStore) Decrypt(ciphertext string, keyVersion int) ([]byte, error)

Decrypt decrypts base64-encoded ciphertext using the key at the given version. The nonce is expected to be prepended to the ciphertext.

func (*KeyStore) Encrypt

func (ks *KeyStore) Encrypt(plaintext []byte) (string, error)

Encrypt encrypts plaintext using AES-256-GCM with the current key version. Returns base64-encoded ciphertext (nonce prepended to ciphertext).

Jump to

Keyboard shortcuts

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