Help us shape the future of Go! Take the 2026 Go Developer Survey

secrets

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package secrets provides authenticated encryption for credentials stored at rest (e.g. workspace provider configs), backed by Google Tink. Tink ciphertext carries the key id, so key rotation is native (a keyset can hold multiple keys with one primary for encryption). The keyset is loaded from config as a base64-encoded cleartext keyset today; swapping in a KMS-wrapped keyset later is a load-time change that leaves Encrypt/Decrypt callers untouched.

Index

Constants

This section is empty.

Variables

View Source
var ErrCiphertext = errors.New("invalid or corrupt ciphertext")

ErrCiphertext is returned when a stored value cannot be decrypted.

Functions

func GenerateKeysetBase64

func GenerateKeysetBase64() (string, error)

GenerateKeysetBase64 mints a fresh AES-256-GCM keyset and returns it base64-encoded — for seeding env config and tests.

func Retire

func Retire(keysetBase64 string) (string, error)

Retire drops every key but the primary from the keyset and returns it base64-encoded. Run it only once every stored value is under the primary key (see Cipher.Current): ciphertext written under a dropped key can no longer be decrypted.

func Rotate

func Rotate(keysetBase64 string) (string, error)

Rotate adds a new AES-256-GCM key to the keyset, makes it the primary and returns the new keyset base64-encoded. Every earlier key stays, so ciphertext written under it still decrypts.

Types

type Cipher

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

Cipher encrypts and decrypts secret values with a Tink AEAD primitive.

func NewCipher

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

NewCipher builds a Cipher from a base64-encoded Tink keyset. It fails fast (caller wires this at boot) when the keyset is missing or malformed.

func (*Cipher) Current

func (c *Cipher) Current(value string) (bool, error)

Current reports whether a stored value is sealed under the primary key. Tink ciphertext starts with the byte 1 and the 4-byte big-endian id of the key that sealed it.

func (*Cipher) Decrypt

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

Decrypt reverses Encrypt.

func (*Cipher) Encrypt

func (c *Cipher) Encrypt(plaintext []byte) (string, error)

Encrypt seals plaintext and returns a base64 string safe to store in a text column.

func (*Cipher) Rewrap

func (c *Cipher) Rewrap(value string) (rewrapped string, changed bool, err error)

Rewrap returns value sealed under the primary key, and whether it had to change: a value that is already current comes back as it is, so re-encrypting is idempotent.

Jump to

Keyboard shortcuts

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