Articles

Lost a device or your keys? How recovery works with end-to-end encryption

If you have just lost a device: start with what to do now. If you are setting up a service that uses end-to-end encryption, the rest of this article explains why recovery works the way it does, and how to set it up so a loss is an inconvenience instead of a disaster.

Why can't the provider just reset my key?

With ordinary services, "forgot password" works because the provider can read your data and simply lets you set a new password. With end-to-end encryption, your data is encrypted with keys that exist only on your devices. The provider stores ciphertext it cannot open.

So there is nothing for the provider to reset. A service that can restore your data without any of your keys is, by definition, a service that can decrypt it. Apple says this plainly for its Advanced Data Protection: if you lose access, "Apple will not have the encryption keys to help you recover it" (iCloud data security overview).

Recovery therefore has to be arranged before the loss, by putting a second way to decrypt somewhere safe.

What are the ways to recover an end-to-end encrypted account?

Every service uses some mix of three:

path what it is what it protects against what it costs you
another device a second phone, laptop or tablet that already has access losing one device nothing extra, but a fire or theft can take them all
a recovery key a secret you keep offline, on paper or a drive losing every device keeping it safe, and knowing where it is in five years
another person someone who can help you back in, or re-share to you losing every device and the key trusting them, and their availability

How three well-known services use them:

Notice the common rule: every recovery path is also an access path. A recovery key on paper opens your data for whoever finds the paper. A trusted contact with takeover rights is trusted with your data. Choose recovery paths you would be comfortable seeing used by someone other than you.

How does a recovery key work, technically?

In many designs the recovery key is simply one more reader, either of each value or of an account key that unlocks them. When a value is encrypted, it is encrypted to each of your devices and to the recovery key. Lose every device, and the recovery key still decrypts everything. (Other designs differ: 1Password's Emergency Kit holds your sign-in secrets, and Apple's recovery key works together with a trusted phone number and an Apple device.)

You can see this with the age encryption tool, which encrypts one file to several keys at once. The following run is real, with version 1.4.0, whose age-keygen makes post-quantum keys by default. Your keys will differ, and the long public keys are shortened here.

Make a device key and a recovery key, and encrypt a value to both:

Terminal
$ age-keygen -o laptop.txt
Public key: age1pq1q2mx62jhksvwtnzs3jeg5…
$ age-keygen -o recovery.txt
Public key: age1pq1lxn9lk3542kx3sfws2qlz…
$ age-keygen -y laptop.txt > readers.txt
$ age-keygen -y recovery.txt >> readers.txt
$ printf 'ghp_exampletoken\n' | age -R readers.txt -o github-token.age

(Versions before 1.4.0 make classic X25519 keys with the same command. The steps work the same way, and version 1.4.0's age command warns whenever it encrypts or decrypts with a classic key. See What is an age key?.)

Now "lose" the laptop, and recover with only the recovery key:

Terminal
$ mv laptop.txt laptop.txt.lost
$ age -d -i recovery.txt github-token.age
ghp_exampletoken

Set up a new laptop, and encrypt again to the new key and the recovery key, leaving the lost laptop out:

Terminal
$ age-keygen -o new-laptop.txt
Public key: age1pq168z8zavu3p7swp27xu7rv…
$ { age-keygen -y new-laptop.txt; age-keygen -y recovery.txt; } > readers.txt
$ age -d -i recovery.txt github-token.age | age -R readers.txt -o github-token.age.new
$ mv github-token.age.new github-token.age
$ age -d -i new-laptop.txt github-token.age
ghp_exampletoken
$ age -d -i laptop.txt.lost github-token.age
age: error: no identity matched any of the recipients
age: report unexpected or unhelpful errors at https://filippo.io/age/report

The lost laptop's key no longer opens the current file. It can still open any old copy of the file it already had, which is why the next section says to change the secret itself.

What should I do right after losing a device?

  1. Remove the device from every service it could access, from another device or with your recovery key. In some end-to-end designs, SecureSecretStore's among them, this re-encrypts your data to the keys that remain.
  2. Treat every secret the device could read as exposed. Removing the device stops it reading new versions. A thief with the device may already hold the old ones. Change the value at its source: issue a new API key at the provider, change the password, revoke the token.
  3. Sign out the device's sessions and revoke its API keys, if the services offer it.
  4. Add a new device with its own new key, and compare its fingerprint when you approve it (see Check a fingerprint).
  5. If you used your recovery key, consider it seen. Make a new one, add it as a reader, and remove the old one.

How do I store a recovery key so it survives?

An age secret key is one line: 77 characters starting AGE-SECRET-KEY-PQ-1 for a post-quantum key, or 74 starting AGE-SECRET-KEY-1 for a classic one. That is short enough to print and type back.

Terminal
$ age-keygen -y
AGE-SECRET-KEY-PQ-1…   (typed back, with one character wrong)
age-keygen: error: failed to parse input: error at line 1: malformed secret key: invalid checksum
age-keygen: report unexpected or unhelpful errors at https://filippo.io/age/report

A key typed in lowercase fails too (unknown identity type), so keep the capitals.

How do I know my recovery setup actually works?

Test it, once when you set it up and again every year or so. Most recovery failures are discovered at the worst possible moment: the paper was lost, the key was never added to new data, or the trusted contact changed phones.

A test takes two minutes:

  1. Take the recovery key out of storage, on a computer you trust.
  2. Decrypt one real, recent value with only the recovery key, typed or pasted at the prompt instead of saved to a file: age -d -i - github-token.age, then the key, then Ctrl-D. Secure deletion is unreliable on SSDs and with snapshots and backups, so never writing the key to disk is the safer habit.
  3. Put the key back.

If step 2 fails, your recovery key is not a reader on recent data, and you have found out in time.

What about shared and team accounts?

Teams have one more path: another member who can still decrypt can re-share to your new key. That is why a shared vault should always have at least two owners. A vault with one owner who loses every device and the recovery key is as unrecoverable as a personal one.

How does SecureSecretStore handle a lost device or key?

SecureSecretStore is not open yet. In its design, every device and agent runtime holds its own key pair, so a lost device is removed from any other device, and the client re-encrypts your secrets to the keys that remain. Before your first real vault opens, you create a recovery kit: a second key pair whose public half is a reader on everything you own, downloaded or printed, and confirmed by typing its last 6 characters. If you lose every device, the kit approves a new one; in a shared vault, another owner can also re-share to you. Without a device, the kit or another owner, the values are gone, and no one, including SecureSecretStore, can recover them. The site says so before you sign up.

The details are in A key per device, and the recovery kit.

For agents and tools: llms.txt. AI version of this article.