Passphrase-encrypted export files for moving app data between phones
encryptionaes-gcmpbkdf2exportbackupfile-formatandroid
When an app keeps personal data only on the device (no account, no server), the way to move it to a new phone is a file the user exports, carries, and imports, protected by a passphrase they choose. The Keyboard app's personal-data export is a compact, reusable design.
File format (Keyboard KBDATA)
magic "KBDATA" | version byte | PBKDF2 iteration count | salt | GCM nonce | AES-256-GCM(ciphertext + tag)
- Key derivation: PBKDF2-HMAC-SHA256, 600,000 iterations (the OWASP 2023 figure for SHA-256), random salt per file. Storing the iteration count in the header lets future versions raise it.
- Cipher: AES-256-GCM with a random 96-bit nonce. GCM's tag authenticates the whole payload, so a wrong passphrase and a tampered file both fail cleanly.
- Payload: JSON of the user's data (words with usage counts, word pairs, saved emails and numbers, shortcuts).
- Derivation takes under a second on a phone; still show progress UI.
Import semantics
- Merge, do not replace, and merge counts with the max, not the sum, so importing the same file twice changes nothing.
- On conflicts the user decides (for shortcuts: "The file's" or "Mine").
- A wrong passphrase or a foreign file must change nothing.
UX rules
- A plaintext export (the SMS app offers CSV/JSON) must require an explicit confirmation, with the password option shown first.
- Passphrase fields need a show/hide toggle. Android trap: setting
isSingleLine = trueon a passwordEditTextsilently unmasks it; set thetransformationMethodinstead. - Data that is in the export should be excluded from automatic Android backups, so the user stays in control of where it goes.
Sync later
If sync is ever wanted, upload the same encrypted blob; the server never sees plaintext.
See also
- E2E key management that never loses a key (keyring, backup, re-wrap)
- App lock, PINs and brute-force lockout on Android