harbor0APIBeta

Beta. The harbor0 API is still in beta, so routes and responses may change before it is final. What beta means

Unlocking the account key

Before you can read anything on an encrypted account, you unwrap its master key and derive the working keys from it. This happens once per run.

1. Fetch the wrapped keys

curl -s https://api.harbor0.com/v1/e2ee -H "Authorization: Bearer $HARBOR0_TOKEN"
{
  "e2ee": {
    "enabled": true,
    "enabledAt": "2026-10-25T08:14:51.120Z",
    "passphrase": {
      "v": 1,
      "kdf": "argon2id",
      "salt": "igLzw4VoOBRJyOOVhOfttQ",
      "memoryKiB": 65536,
      "iterations": 3,
      "parallelism": 1,
      "iv": "mo69IvzDurQ2suFq",
      "ciphertext": "hdN0WYKM4_0sS4tW37mxPHl37Vdj6oGM30hMM2q29TZhbsT01aPeW-p379fNoDlL"
    },
    "recovery": {
      "v": 1,
      "kdf": "hkdf",
      "salt": "ocTg9-NihaoRTkEsnaOKig",
      "iv": "Fll0YBxs2KWqufrp",
      "ciphertext": "xVrmbUqo9IgxysogM4kuZb2wk0QgILybjSp_k1IkhosC6JS_naHmWLb8ToNcmBVv"
    },
    "devices": [],
    "migration": { "totalFiles": 412, "doneFiles": 412, "complete": true, "…": "…" },
    "decryptingSince": null,
    "…": "…"
  }
}

passphrase and recovery are envelopes: the same master key, wrapped two ways. All their binary fields are base64url without padding. devices is always empty for a token, because each app's own copy is for that app alone.

2. Unwrap the master key

With the passphrase

  1. Normalize the passphrase to Unicode NFKC and encode it as UTF-8.
  2. Run Argon2id over it with the envelope's salt, iterations, memoryKiB and parallelism, producing 32 bytes. Use the values from the envelope rather than fixed ones: they can differ between accounts.
  3. Use those 32 bytes as an AES-256-GCM key to open ciphertext with the envelope's 12-byte iv and the associated data harbor0/e2ee/v1/master (the ASCII text). The last 16 bytes of ciphertext are the GCM tag.
  4. The result must be exactly 32 bytes: the master key.

A wrong passphrase makes the GCM tag check fail. Report it as a wrong passphrase.

With the recovery key

A recovery key is 20 random bytes, written as 32 characters of Crockford base32 in groups of four: S33W-DHE4-RF1C-3G5Z-QTYV-SEXT-Q6WB-FDNN.

  1. Upper-case it and remove spaces and dashes. Read O as 0, I and L as 1, and U as V, as people often mistype those.
  2. Check that 32 characters from 0123456789ABCDEFGHJKMNPQRSTVWXYZ remain, and decode them, 5 bits per character, most significant first, into 20 bytes.
  3. Derive a key: HKDF-SHA256 with the 20 bytes as input, the envelope's salt as salt, harbor0/e2ee/v1/recovery as info, and 32 bytes of output.
  4. Open ciphertext with that key exactly as in step 3 above (same associated data, harbor0/e2ee/v1/master).
import { hkdfSync, createDecipheriv } from 'node:crypto';
import { argon2id } from 'hash-wasm'; // npm install hash-wasm

const b64 = (s) => Buffer.from(s, 'base64url');

function open(key, iv, sealed, aad) {
  const d = createDecipheriv('aes-256-gcm', key, iv);
  d.setAAD(aad);
  d.setAuthTag(sealed.subarray(-16));
  return Buffer.concat([d.update(sealed.subarray(0, -16)), d.final()]); // throws on a wrong key
}
const MASTER_AAD = Buffer.from('harbor0/e2ee/v1/master');

export async function unlockWithPassphrase(envelope, passphrase) {
  const kek = await argon2id({
    password: passphrase.normalize('NFKC'),
    salt: b64(envelope.salt),
    iterations: envelope.iterations,
    memorySize: envelope.memoryKiB,
    parallelism: envelope.parallelism,
    hashLength: 32,
    outputType: 'binary',
  });
  return open(Buffer.from(kek), b64(envelope.iv), b64(envelope.ciphertext), MASTER_AAD);
}

export function unlockWithRecovery(envelope, recoveryKey) {
  const recovery = parseRecoveryKey(recoveryKey); // 20 bytes, see the full example
  const kek = Buffer.from(
    hkdfSync('sha256', recovery, b64(envelope.salt), 'harbor0/e2ee/v1/recovery', 32),
  );
  return open(kek, b64(envelope.iv), b64(envelope.ciphertext), MASTER_AAD);
}

The recovery key parser is in the complete examples.

3. Derive the working keys

Everything else uses keys derived from the master key with HKDF-SHA256, an empty salt (which HKDF treats as 32 zero bytes) and these info strings:

KeyinfoLengthUsed for
File-wrapping keyharbor0/e2ee/v1/file-keys32 bytesUnwrapping each file version's content key (Decrypting files)
Name keysharbor0/e2ee/v1/names64 bytesBytes 0–31: AES-256-GCM key for names. Bytes 32–63: HMAC-SHA256 key for name IVs (Decrypting file names)
const hkdf = (master, info, length) =>
  Buffer.from(hkdfSync('sha256', master, Buffer.alloc(0), info, length));

export function accountKeys(master) {
  const names = hkdf(master, 'harbor0/e2ee/v1/names', 64);
  return {
    fileWrap: hkdf(master, 'harbor0/e2ee/v1/file-keys', 32),
    nameEnc: names.subarray(0, 32),
    nameMac: names.subarray(32, 64),
  };
}

Check your work

Use the test vectors: their passphrase correct horse fi battery (note the fi ligature, which NFKC turns into fi) and recovery key S33W-DHE4-RF1C-3G5Z-QTYV-SEXT-Q6WB-FDNN must both unwrap to the master key AQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGRobHB0eHyA (the bytes 1 to 32).