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:AES-256-GCM Encryption
All sensitive data is encrypted with AES-256-GCM (Galois/Counter Mode).Encryption Process
Decryption Process
What Gets Encrypted
| Data | Encryption |
|---|---|
| Secret values | AES-256-GCM |
| Secret key names | AES-256-GCM |
| API key labels | AES-256-GCM |
| System key scopes | AES-256-GCM (JSON array) |
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
- 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)?
| Property | API Keys | Passwords |
|---|---|---|
| Entropy | 128 bits | ~40 bits |
| Attack | Brute-force keyspace | Dictionary attack |
| Hash choice | Fast (SHA-256) | Slow (Argon2id) |
Summary
| Component | Algorithm | Purpose |
|---|---|---|
| Master key | 256-bit random | Root of trust |
| Key derivation | HKDF-SHA256 | Derive encryption + HMAC keys |
| Data encryption | AES-256-GCM | Encrypt secrets, labels, scopes |
| Lookup hashing | HMAC-SHA256 | Deterministic keyed lookups |
| API key hashing | SHA-256 | Store key hashes for auth |
Next Steps
API Reference
Explore the Keyflare API endpoints.
CLI Reference
Learn the kfl CLI commands.
