secrets

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0 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 secrets encrypts provider credentials, OIDC client secrets, TOTP seeds and other write-only values at rest with AES-256-GCM.

Ciphertext layout: version (1 byte) | key id (4 bytes) | nonce (12) | sealed. The key id is the first 4 bytes of SHA-256(key), so data sealed with a previous key still opens after rotation. Callers pass associated data that names the row and field ("provider:<id>:credentials"), which stops a ciphertext from being copied onto another row.

Index

Constants

This section is empty.

Variables

View Source
var ErrDecrypt = errors.New("secrets: cannot decrypt value")

ErrDecrypt is returned when a value can't be opened with any known key.

Functions

func GenerateKey

func GenerateKey() string

GenerateKey returns a new random 32-byte key, base64-encoded.

func LoadOrCreateKeyFile

func LoadOrCreateKeyFile(path string) (string, bool, error)

LoadOrCreateKeyFile reads a base64 key from path, creating the file with a fresh key (mode 0600) when it doesn't exist yet.

Types

type Box

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

Box seals and opens values. The zero value is not usable; use New.

func New

func New(current []byte, previous ...[]byte) (*Box, error)

New returns a Box that seals with current and opens with current or any previous key.

func (*Box) CurrentKeyID

func (b *Box) CurrentKeyID() [4]byte

CurrentKeyID is the id new values carry at bytes 1–4: the first 4 bytes of SHA-256 of the current key.

func (*Box) NeedsRotation

func (b *Box) NeedsRotation(ciphertext []byte) bool

NeedsRotation reports whether ciphertext was sealed with a previous key.

func (*Box) Open

func (b *Box) Open(ciphertext []byte, ad string) ([]byte, error)

Open decrypts a value sealed with Seal and the same associated data.

func (*Box) OpenString

func (b *Box) OpenString(ciphertext []byte, ad string) (string, error)

OpenString is Open for strings.

func (*Box) Seal

func (b *Box) Seal(plaintext []byte, ad string) ([]byte, error)

Seal encrypts plaintext bound to associated data ad.

func (*Box) SealString

func (b *Box) SealString(s, ad string) ([]byte, error)

SealString is Seal for strings.

Jump to

Keyboard shortcuts

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