crypto

package
v1.8.9 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: Apache-2.0 Imports: 10 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 crypto implements decrypt-only support for the field-level encrypted config values produced by the control plane at export time (see docs/zh_cn/sys_design/config_file_field_encryption.md). Key material is distributed via a shared keyring file; BFE never encrypts.

Index

Constants

View Source
const Marker = "enc$v1$"

Marker is the envelope prefix marking a field value as ciphertext:

enc$v1$<base64( keyID(1B) | nonce(12B) | AES-256-GCM(plaintext)+tag(16B) )>

Values without the marker are legacy plaintext and pass through unchanged.

Variables

View Source
var ErrNoKeyring = errors.New("crypto: keyring not configured (Security.KeyFile)")

ErrNoKeyring is returned when a marker-prefixed value is decrypted without a keyring (Security.KeyFile not configured).

Functions

func Decrypt

func Decrypt(value string, kr *Keyring) (string, error)

Decrypt decrypts a single enc$v1$ envelope with the keyring. The key is selected by the keyID carried in the envelope itself, so ciphertexts encrypted with different keyIDs coexist naturally during rotation.

Error messages deliberately contain only the keyID and envelope length — never ciphertext or plaintext material.

func HasMarker

func HasMarker(value string) bool

HasMarker reports whether a config field value is an enc$v1$ ciphertext envelope rather than plaintext.

Types

type Keyring

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

Keyring holds all in-service file-encryption keys, keyed by keyID. Multiple keyIDs coexist during rotation: decryption selects the key by the keyID embedded in each envelope, so old and new ciphertexts are both readable until the old keyID is retired.

func LoadKeyringFile

func LoadKeyringFile(path string) (*Keyring, error)

LoadKeyringFile parses the shared TOML keyring file format (same file is used by the control plane to encrypt):

ActiveKeyID = 2
[Keys]
  1 = "<base64 of 32-byte key>"   # old key: decrypt legacy ciphertext
  2 = "<base64 of 32-byte key>"   # current key

ActiveKeyID is optional on the BFE (decrypt-only) side. Parsing is strict and fail-closed: malformed lines, duplicate keyIDs and bad key material are all errors.

func (*Keyring) ActiveKeyID

func (kr *Keyring) ActiveKeyID() byte

ActiveKeyID returns the keyID marked active in the keyring file (informational on the BFE decrypt-only side).

func (*Keyring) Key

func (kr *Keyring) Key(id byte) ([keyLen]byte, bool)

Key returns the key material for a keyID.

func (*Keyring) KeyIDs

func (kr *Keyring) KeyIDs() []byte

KeyIDs returns the sorted in-service keyIDs (for status/monitoring).

Jump to

Keyboard shortcuts

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