sealer

package
v1.24.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 8 Imported by: ? modules, 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

Overview

Package sealer encrypts and authenticates small payloads with keys shared by a group of servers, so that a value sealed by one server can be opened by any other server holding one of the same keys.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalid = errors.New("sealer: invalid sealed value")

ErrInvalid is returned by Open for any sealed value it cannot open: truncated, tampered with, sealed with an unknown key, or opened with different associated data. The causes are deliberately indistinguishable.

Functions

This section is empty.

Types

type AESGCM

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

AESGCM is a Sealer using AES-256-GCM with a random 96-bit nonce per Seal.

Wire format: nonce (12 bytes) | ciphertext (len(plain) bytes) | tag (16 bytes). Each AES key is the SHA-256 of a configured key string.

It holds a list of keys to allow rotation: Seal uses the first key, and Open tries each key in order. To rotate, deploy with the new key added last, then move it first, then drop the old one, waiting at each step for the rollout and for values sealed with the old key to expire.

Each Seal draws a fresh random nonce, which keeps a key safe for about 2^32 seals.

func NewAESGCM

func NewAESGCM(keys []string) (*AESGCM, error)

NewAESGCM returns an AESGCM sealing with keys[0] and opening with any of keys. It fails if keys is empty or holds an empty key.

Keys are secrets: use high-entropy values. To use one secret for several purposes, bind the purpose into aad, so that a value sealed for one purpose doesn't open for another.

func (*AESGCM) Open

func (s *AESGCM) Open(dst, sealed, aad []byte) ([]byte, error)

Open implements Sealer.

func (*AESGCM) Overhead

func (s *AESGCM) Overhead() int

Overhead implements Sealer.

func (*AESGCM) Seal

func (s *AESGCM) Seal(dst, plain, aad []byte) ([]byte, error)

Seal implements Sealer. It fails only if the system random source fails.

type Sealer

type Sealer interface {
	// Seal encrypts and authenticates plain, authenticates aad, and appends the result to dst.
	// aad is not part of the output: Open must be given the same aad.
	// The result is self-contained: it carries everything Open needs besides the key and aad.
	// Sealing the same input twice gives different results.
	// dst, including its spare capacity, must not overlap plain or aad.
	Seal(dst, plain, aad []byte) ([]byte, error)

	// Open authenticates and decrypts sealed, a value returned by Seal, and appends the plaintext to dst.
	// It returns ErrInvalid if sealed was not produced by Seal with an accepted key and the same aad.
	// dst, including its spare capacity, must not overlap sealed or aad. This holds even when
	// the value opens: a failed attempt with an earlier key may clear dst's spare capacity.
	Open(dst, sealed, aad []byte) ([]byte, error)

	// Overhead is the number of bytes Seal adds to the plaintext.
	Overhead() int
}

Sealer encrypts and authenticates data.

Implementations are safe for concurrent use.

Jump to

Keyboard shortcuts

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