# Recover a Recipient Key

Your recipient key is the only key that opens your objects. To survive losing it, split it among custodians when you create it. Any `t` of the `n` custodians can then restore it together, and fewer than `t` learn nothing about it. This guide uses 2 of 3. The CLI accepts any `t` from 2 up to `n`, and `n` up to 255.

The split happens in `keygen`, so plan it before you create the key. A key created without `--recovery` can't be split afterwards. To add recovery then, create and register a new key with it (see [Keys](/docs/vaults/concepts/keys/#recipient-keys)).

## 1. Each custodian creates a key

Each custodian runs, on their own machine:

```bash
octet-vault keygen --out custodian.key --label "<custodian name>"
octet-vault recovery public-key --key custodian.key --out custodian-1.pub
```

and sends you `custodian-1.pub` (or `-2`, `-3`). It holds only the public key. Each custodian keeps `custodian.key` and its passphrase safe: a custodian who loses them can't help restore.

## 2. Create the recipient key with recovery

```bash
octet-vault keygen --out vault.key --label "<your company> vault" \
    --recovery 2-of-3 \
    --custodian custodian-1.pub --custodian custodian-2.pub --custodian custodian-3.pub
```

Next to `vault.key` this writes:

- `vault.recovery.json`, the recovery record. It holds no secret. Keep copies with you and with every custodian.
- `vault.share-1.json`, `vault.share-2.json` and `vault.share-3.json`, one per custodian, in the order of the `--custodian` flags. Each is encrypted to its custodian's key.

Send each custodian their share file and a copy of the recovery record. Then register `vault.key` as in the [Quickstart](/docs/vaults/getting-started/quickstart/#5-create-and-register-the-recipient-key).

## 3. Restore the key

When you need the key back, the person restoring it creates a fresh key to receive the shares, and sends its public key to the custodians:

```bash
octet-vault keygen --out restorer.key --label "restore"
octet-vault recovery public-key --key restorer.key --out restorer.pub
```

Two custodians each re-encrypt their share to that key:

```bash
octet-vault recovery transfer --recovery vault.recovery.json --share vault.share-1.json \
    --key custodian.key --restorer-key restorer.pub --out transfer-1.json
```

`transfer` checks the share against the recovery record before it re-encrypts it, and the share exists in plaintext only in the custodian's memory. Each custodian sends back their `transfer-<n>.json`.

The person restoring combines them:

```bash
octet-vault recovery recover --recovery vault.recovery.json \
    --share transfer-1.json --share transfer-2.json \
    --key restorer.key --out vault-restored.key
```

`recover` checks each share and names the first one that fails. It refuses fewer shares than the split needs, and the same share twice. It then checks that the restored key matches the public key in the recovery record, and writes it to `vault-restored.key` under a new passphrase that it asks for.

`vault-restored.key` opens every object sealed to the original key. You don't need to register it again: the vault already knows its public key.
