crypto

package
v1.7.2 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package crypto provides authenticated symmetric encryption (AES-256-GCM) for secrets stored at rest, such as registry credentials. The key is generated once and persisted alongside the other server secrets.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cipher

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

Cipher seals and opens short secrets with AES-GCM. The nonce is random per message and prepended to the ciphertext; output is base64 for DB storage.

func New

func New(key []byte) (*Cipher, error)

New returns a Cipher for a 16/24/32-byte key (32 = AES-256).

func (*Cipher) Decrypt

func (c *Cipher) Decrypt(enc string) (string, error)

Decrypt reverses Encrypt. A wrong key or tampered ciphertext yields an error.

func (*Cipher) Encrypt

func (c *Cipher) Encrypt(plain string) (string, error)

Encrypt seals plaintext and returns base64(nonce || ciphertext).

func (*Cipher) Fingerprint added in v1.7.0

func (c *Cipher) Fingerprint(plain string) string

Fingerprint returns a deterministic, keyed digest of plain: the same value always yields the same fingerprint, a different value yields a different one, and the digest cannot be reversed to recover plain. It must stay a keyed HMAC, never a bare sha256(plain) — an unkeyed hash would let an attacker precompute digests of common/weak values and match them against a fingerprint shown in a UI, defeating the point of masking. The HMAC key is a subkey HKDF-derived from the AES key (see New), never the raw AES key itself, so the two primitives never share key material.

Jump to

Keyboard shortcuts

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