Encryption and Key Management

Encryption is two separate problems: protect the bytes and protect the keys. Most failures happen in key management.

Start With A Threat Model

ThreatExampleUseful controls
casual device accessfriend opens unlocked laptopapp lock, biometric/PIN, OS account lock
stolen devicephone or laptop is lostOS disk encryption, app lock, encrypted backups
backup readercloud drive or exported file leaksbackup encryption with separate key/password
rooted/malware deviceattacker controls OSlimited protection; focus on minimizing stored secrets
cloud compromiseserver backup leakslocal-only or end-to-end encrypted backup/sync

Storage Rules

  • Store keys in Android Keystore, iOS Keychain, macOS Keychain, Windows Credential Manager, libsecret, Tauri Stronghold, or equivalent platform vaults.
  • Do not store encryption keys next to plaintext data.
  • Do not hardcode secrets in source code.
  • Design key loss behavior before shipping encryption.
  • Encrypt backups separately from the live database when users move files through cloud storage.

Full-DB vs Field Encryption

ApproachProsCons
Full-database encryptionbroad coverage, simple mental modellibrary integration and migration constraints; exact SQLCipher docs still need verification here
Field encryptionselective protection, works with existing DBquery/index limits, easy to miss fields
Encrypted backup onlysimple recovery protectionlive local DB still relies on OS/app lock
OS disk encryption onlylow implementation costweak if app/account is unlocked

Recovery Design

Every encrypted app needs answers to these questions:

  1. Can the user restore on a new device?
  2. Is the restore key a password, platform vault item, recovery code, or account key?
  3. What happens when the password is forgotten?
  4. Can support recover the data? Should they be able to?
  5. Are backups encrypted before leaving the device?

Warning: SQLCipher/full-database encryption needs fresh official verification before this topic prescribes exact Android or desktop integration steps.