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

ThreatMinimum control
casual snoopingapp lock plus OS device lock
stolen deviceOS disk encryption plus app lock
leaked backup fileencrypted backup with password or recovery key
cloud compromiseencrypt before upload; server cannot read backup
rooted/malware devicelimit 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 modelWorks on new device?Support can recover?Fit
device-bound keynonolocal-only secrets and low recovery expectations
user passwordyes, if rememberednoprivate backups and vaults
recovery codeyesnohigh-value private data
account escrowyesmaybeconvenience over strict zero-knowledge
no recoverynonoacceptable 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.