Add Encryption With Key Recovery
Design recovery before writing encryption code. If the user loses the key, encryption turns a normal restore problem into permanent data loss.
Step 1: Pick The Threat Model
| Threat | Minimum control |
|---|---|
| casual snooping | app lock plus OS device lock |
| stolen device | OS disk encryption plus app lock |
| leaked backup file | encrypted backup with password or recovery key |
| cloud compromise | encrypt before upload; server cannot read backup |
| rooted/malware device | limit stored secrets; do not promise full protection |
Write this in the product spec. Encryption without a threat model creates false confidence.
Step 2: Separate Live Data From Backup Protection
Live app data
local DB or files
protected by OS storage, app lock, and optional DB or field encryption
Backup artifact
exported file
encrypted before leaving the device
restorable with password, recovery key, or account-held key material
This split lets you ship safe encrypted backup even if full-database encryption needs more platform work.
Step 3: Store Keys In A Platform Vault
Use platform storage for long-lived keys:
- Android: Keystore-backed key material
- iOS/macOS: Keychain
- Windows: Credential Manager or DPAPI-backed library
- Linux: libsecret or a documented password flow
- Tauri: Stronghold is a candidate for app-managed secrets
Do not put keys in the same directory as the plaintext database.
Step 4: Choose Recovery Behavior
| Recovery model | Works on new device? | Support can recover? | Fit |
|---|---|---|---|
| device-bound key | no | no | local-only secrets and low recovery expectations |
| user password | yes, if remembered | no | private backups and vaults |
| recovery code | yes | no | high-value private data |
| account escrow | yes | maybe | convenience over strict zero-knowledge |
| no recovery | no | no | acceptable only with very clear warning |
Step 5: Test The Negative Paths
Given an encrypted backup
When the user enters the wrong password
Then restore fails without modifying current local data
Given a clean install on a new device
When the user provides the correct recovery secret
Then restore succeeds and all row counts match the manifest
Also test cancelled unlock, missing secure-store item, corrupted backup, and unsupported backup version.
Warning: Do not prescribe SQLCipher integration from this topic yet. The plan could not access current SQLCipher docs, so full-database encryption remains a source-to-verify follow-up.