- Docs
- Security
- Crypto and secrets
Crypto and secrets
Encrypt and sign data with one key service, and read named credentials from env or Vault.
crypto encrypts and signs payloads and fields at rest or in transit; secrets looks up named credentials (API keys, connection strings). They resolve independently; passwords are not encrypted (Password hashing).
Quick start
Section titled “Quick start”config.Default() ships a deterministic dev key so tests run real encryption; that key is public, so anything encrypted under it is recoverable. The local adapter accepts it only when explicitly allowed — set allow_dev_key: true (development only) or run with ZEVER_ENV=dev|test|development. Any other environment must set a real key.
CRYPTO_ADAPTER=localCRYPTO_KEY=MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDE=CRYPTO_ALLOW_DEV_KEY=trueSECRETS_ADAPTER=envSECRETS_PREFIX=ZEVERCRYPTO_KEY=prod-base64-key-hereexport ZEVER_STRIPE_KEY=sk_test_examplecr, err := c.Crypto() // key missing, malformed, or dev key without allowsec, err := c.Secrets() // prefix invalidsign_key (optional) must decode to 64 bytes. STRIPE_KEY resolves to the exported ZEVER_STRIPE_KEY; without env, config.Default() still resolves but uses the dev key (allowed only via allow_dev_key or a dev ZEVER_ENV). See the crypto and secrets reference.
Pick an adapter
Section titled “Pick an adapter”crypto: local (default, AES-256-GCM) or kms (envelope encryption via key_id, key_ids, region, endpoint, use_envelope; needs a real client through NewWithClient). secrets: env (default, <PREFIX>_<NAME>, prefix defaults to ZEVER) or vault (KV v2, Secrets). key_ids holds prior IDs so rotation decrypts old values while new writes use key_id.
Rotate the crypto key for stored fields
Section titled “Rotate the crypto key for stored fields”- Generate a CSPRNG key and inject it through env.
- Dual-read: decrypt old, re-encrypt new, persist.
- Track old-key rows to zero.
- Remove the old key and verify decrypts.
Name the encrypted fields and their key generation in one place, such as the migration runbook.
Production checklist
Section titled “Production checklist”- Real key from a CSPRNG, in env or a mounted file, kept in a secret manager.
allow_dev_keyunset (or false) andZEVER_ENVnot dev/test/development — otherwiseOpenfails withDevKeyError.- Resolve and audit both
cryptoandsecrets. - Never log raw option maps; use
cfg.RedactedServices()orconfig.Redact. Errors name services and fields, never values.
Troubleshooting
Section titled “Troubleshooting”Production resolves but old rows decrypt to garbage
Rows encrypted under a different key, often the dev key. Re-encrypt them during migration.
Secrets lookup misses
The env name lacks the prefix or its boundary underscore (STRIPE_KEY vs ZEVER_STRIPE_KEY).
Open rejects the secrets prefix
Empty, or contains a slash, .., or spaces. Use a plain prefix such as ZEVER.
Open rejects the dev key with DevKeyError
The deterministic public key was supplied without an explicit allow. Set a real crypto.options.key, or set allow_dev_key: true / ZEVER_ENV=dev|test|development for local development.
Key material appears in logs
Some path logs raw options. Route all display through cfg.RedactedServices() or config.Redact.