Skip to main content

Encryption

Keyflare uses industry-standard encryption algorithms via the Web Crypto API.

Overview

Master Key

The MASTER_KEY is the single root of trust:
  • Storage: Cloudflare Worker Secret
  • Format: Base64-encoded 256-bit (32-byte) key
  • Set via: wrangler secret put MASTER_KEY
  • Lives in: Worker runtime memory only

Key Derivation (HKDF)

We use HKDF to derive two separate keys from the master key:
This separation ensures that even if the HMAC key were exposed, the encryption key remains independent.

AES-256-GCM Encryption

All sensitive data is encrypted with AES-256-GCM (Galois/Counter Mode).

Encryption Process

Decryption Process

What Gets Encrypted

Why GCM?

  • Authenticated encryption — Detects tampering
  • Native to Web Crypto API — No dependencies
  • Fast — Hardware acceleration on most platforms
  • 12-byte IV — Standard for GCM, random per encryption

HMAC-SHA256 for Lookups

To find records by name without storing plaintext, we use HMAC-SHA256:

Use Case: Secret Key Lookup

This allows:
  • Looking up secrets by key name
  • Deduplication (same key name = same hash)
  • No plaintext key names in database

Why HMAC (not plain hash)?

  • Keyed — Requires the HMAC key to compute
  • Deterministic — Same input always produces same output
  • Not reversible — Cannot recover name from hash without key

API Key Hashing

API keys are hashed with SHA-256 for storage:

Storage Strategy

Authentication Flow

Why SHA-256 (not Argon2id)?

API keys have 128 bits of entropy, making brute-force infeasible regardless of hash speed. SHA-256 is native and adds zero dependencies.

Summary

Next Steps

API Reference

Explore the Keyflare API endpoints.

CLI Reference

Learn the kfl CLI commands.