Documentation
¶
Overview ¶
Package cryptoutil provides symmetric encryption primitives used to protect per-user secrets (currently: cloud backup credentials) at rest.
Design goals:
- One key, one algorithm — AES-256-GCM with a 96-bit random nonce.
- Tampering and nonce-reuse are detectable (GCM authentication tag).
- Caller-friendly: ciphertext and nonce are returned as separate byte slices so the storage layer can put each in its own column.
- Key handling: the key is loaded from a base64-encoded environment variable at startup; KeyFromBase64 enforces a 32-byte key length and refuses obviously-empty values to fail closed on a misconfigured deployment.
Index ¶
Constants ¶
View Source
const KeySize = 32
AES-256 key size in bytes.
View Source
const NonceSize = 12
GCM nonce size in bytes (96 bits; the standard recommendation).
Variables ¶
View Source
var ( // ErrInvalidKey is returned when the supplied key is not exactly 32 bytes. ErrInvalidKey = errors.New("cryptoutil: key must be 32 bytes (AES-256)") // ErrInvalidCiphertext is returned when the ciphertext fails authentication // or is malformed. ErrInvalidCiphertext = errors.New("cryptoutil: ciphertext could not be decrypted") )
Functions ¶
func GenerateKey ¶
GenerateKey returns a cryptographically random 32-byte key suitable for AES-256. Intended for development tooling and tests.
func GenerateKeyBase64 ¶
GenerateKeyBase64 returns GenerateKey encoded as standard base64.
Types ¶
type AEAD ¶
type AEAD struct {
// contains filtered or unexported fields
}
AEAD wraps an AES-256-GCM cipher with helper methods. Construct via New or NewFromBase64.
func NewFromBase64 ¶
NewFromBase64 decodes a standard or URL-safe base64 string and constructs an AEAD. Spaces in the input are ignored to tolerate copy-paste artifacts.
Click to show internal directories.
Click to hide internal directories.