How end-to-end encryption works
When an account turns on end-to-end encryption, every file name and every file's contents are encrypted on the person's own devices before they are uploaded. harbor0's servers store only the encrypted forms, so harbor0 cannot read them. To work with such an account through the API, your code does the same: it decrypts what it reads and encrypts what it writes, using keys only the account holder can unlock.
This page explains the design. The next pages show each step in code:
- Unlocking the account key
- Decrypting file names
- Decrypting files
- Uploading to an encrypted account
- Complete examples
Is the account encrypted?
GET /v1/users/me tells you. On an encrypted account, user.e2ee is present:
{
"user": {
"id": "…",
"e2ee": { "enabledAt": "2026-10-25T08:14:51.120Z" },
"…": "…"
}
}On an unencrypted account user.e2ee is absent and nothing on these pages applies.
Remember to send X-Harbor-E2EE: h0e1 on file requests to an encrypted account, to say your code handles the format. Without it they are refused with 403 E2EE_UNSUPPORTED. See Authentication.
The keys
Everything hangs off one random 32-byte master key per account. The server never sees it unwrapped. It stores the master key only in wrapped (encrypted) form, once for each way of unlocking it:
encryption passphrase ──Argon2id──▶ key ─┐
├─ AES-256-GCM unwrap ─▶ master key (32 bytes)
recovery key ──────────HKDF-SHA256──▶ key ─┘
│
┌───────────── HKDF-SHA256 ─────┼────────────────────┐
▼ ▼ ▼
file-wrapping key name key (AES) name MAC key (HMAC)
│ └────────┬───────────┘
unwraps each file version's encrypt and decrypt
own random content key file and folder names
│
AES-256-GCM over the file in 4 MiB chunks- The encryption passphrase is chosen by the account holder. It is separate from their sign-in password and never reaches harbor0.
- The recovery key is a 32-character code (such as
S33W-DHE4-RF1C-3G5Z-QTYV-SEXT-Q6WB-FDNN) shown once when encryption is turned on. Either secret alone unlocks the master key. - Each harbor0 app also keeps its own wrapped copy so it can unlock without asking for the passphrase. Those device copies are never given to access tokens; your code unlocks with the passphrase or the recovery key.
- Every file version gets its own random content key, wrapped by the file-wrapping key and stored at the start of the file. Changing one file never touches another, and a leaked content key opens only that one version.
What the server can and cannot see
| Kept encrypted | Visible to the server |
|---|---|
| File and folder names | Which folder each item is in, and the folder tree |
| File contents | Each file's stored size, which is close to its real size |
| The master key and every content key | When items were created, changed and modified |
| Which items in a folder share a name |
Encrypted names are deterministic: the same name always encrypts to the same token for the same account, so the server can keep names unique within a folder. The price is that it can tell when two items have the same name, though not what the name is.
File types are hidden as well: encrypted uploads are stored as application/octet-stream.
The building blocks
| Purpose | Algorithm |
|---|---|
| Passphrase to key | Argon2id, 32-byte output; cost stored with the envelope (the apps use 64 MiB, 3 passes, 1 lane) |
| Recovery key to key | HKDF-SHA256 with a random 16-byte salt |
| Sub-keys from the master key | HKDF-SHA256 with an empty salt and fixed info strings |
| Wrapping keys, encrypting names and chunks | AES-256-GCM, 12-byte IVs, 16-byte tags |
| Name IVs | First 12 bytes of HMAC-SHA256 of the name |
| Integrity of a stored file | SHA-256 of the stored bytes, kept by the server as contentHash |
All binary values in API responses are base64url without padding (the - and _ alphabet, no =). AES-GCM ciphertexts are always the encrypted bytes followed by the 16-byte tag, which is how WebCrypto, Node.js and Python's cryptography all produce them.
Every AES-GCM operation is bound to its purpose with associated data (for example the text harbor0/e2ee/v1/name for names), so a ciphertext made for one purpose cannot be passed off as another.
Accounts part way through a change
Two states need care:
- Turning encryption on. Files stored earlier are re-encrypted by the person's apps in the background. Until that finishes, a folder can hold both encrypted and plain names, and both encrypted and plain files.
GET /v1/e2eeshows progress undermigration; it is finished whenmigration.completeistrue. - Turning encryption off.
user.e2ee.decryptingSinceis set while the apps decrypt everything back. In this state, store new names and files unencrypted, and still decrypt anything encrypted you read.
So always decide per item: a name is encrypted when it matches ^h0e1\.[A-Za-z0-9_-]+$, and a file is encrypted when its item (or its download) has encrypted: true. Leave anything else as it is.
Looking after the keys
- Ask for the passphrase or recovery key when your program starts, or read it from a secrets manager. Never send it to harbor0 or anywhere else.
- Unlocking with the passphrase is deliberately slow and uses 64 MiB of memory. Unlock once per run and keep the derived keys in memory, not on disk.
- Treat decrypted files and names with the same care as the person's own copies.