crypto

package
v0.17.3 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package crypto encrypts content at rest with AES-256-GCM.

It protects the *content* of documents and blobs — the text of a note, the bytes of an image — never their envelope: identifiers, sources, metadata and timestamps stay clear, because stores filter and join on them. Encrypting the envelope would either break those queries or force deterministic encryption, which leaks equality.

The encryption is applicative, not engine level: sealed values travel to the database as opaque bytes, so the same key protects a SQLite file today and a PostgreSQL cluster tomorrow.

Threat model: a stolen database file, a misplaced backup, a resold disk. A compromised process holds the key and is out of scope.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsSealed

func IsSealed(value []byte) bool

IsSealed reports whether value carries the encryption marker. Migrations rely on it to never seal a value twice.

Types

type Cipher

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

Cipher seals and opens content values.

func NewCipher

func NewCipher(key string) (*Cipher, error)

NewCipher derives a Cipher from key. The key must carry at least 32 bytes of material; it is stretched through HKDF-SHA256, never used raw.

func (*Cipher) Open

func (c *Cipher) Open(value []byte) ([]byte, error)

Open decrypts a value produced by Seal. A value without the marker is returned as is: it predates encryption and is already clear.

func (*Cipher) Seal

func (c *Cipher) Seal(value []byte) ([]byte, error)

Seal encrypts value and prefixes it with the marker. Empty values stay empty: there is nothing to protect, and a marker would advertise a content where there is none.

Jump to

Keyboard shortcuts

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