# Vault and keys

The vault is where Aegis keeps keys and the record of everything done with them. In Aegis Cloud each organisation is one tenant of a vault that qblackbit runs; in Aegis Core the vault is yours.

## Keys, versions and names

You refer to a key by its **name**; the algorithm and material stay inside. A key has **versions**: rotating adds a version that new protection uses, while older versions keep opening and verifying what they protected. Every signature and ciphertext records the version that made it.

- Create: `POST /v1/keys` (Core) or `POST /api/v1/keys` (Cloud), with a name and an algorithm.
- Rotate: `POST /v1/keys/{name}/rotate` (Core).
- Import material made elsewhere: `POST /v1/keys/{name}/import` (Core). The material must pass the algorithm's own key checks first.

## States and dates

A Core key moves through the life cycle of NIST SP 800-57:

| State | New protection (sign, encrypt, encapsulate) | Existing protection (decrypt, decapsulate) |
| --- | --- | --- |
| `pre-active` | No | No: it waits for activation, by hand or by its date |
| `active` | Yes | Yes |
| `suspended` | No | No: a hold, undone by resuming |
| `deactivated` | No | Yes, so old data stays readable |
| `compromised` | No | Yes, and every use is flagged in the audit |
| `destroyed` | No | No: the material is gone |

Activation and deactivation dates are enforced when the key is used (`POST /v1/keys/{name}/dates`). Deleting a key is **scheduled** after a waiting period (`POST /v1/keys/{name}/delete`, cancellable); crypto-shredding with `POST /v1/keys/{name}/destroy` erases every version at once and cannot be undone, which is why it sits under [dual control](https://docs.qblackbit.com/concepts/dual-control.md) by default.

## Export rules

Each key is created with an export policy that never changes: `none` (the default: the private material never leaves), `wrapped` (it leaves only encrypted to an escrow key of the vault) or `plain`. An import never loosens the rules of the key it came from, and exporting sits under dual control by default.

In Aegis Cloud, keys stay in the vault. Exporting a cloud key wrapped to your own key is (Not available yet).

## Envelopes and signatures that describe themselves

`POST /v1/keys/{name}/encrypt` returns an **envelope** (`AGV2`) and `POST /v1/keys/{name}/sign` can return a signature envelope (`AGS2`). Each records the key, the version, the algorithm, the specification revision and what it is bound to, and is parsed strictly. `POST /v1/envelopes/describe` reads that header without opening anything.

That record is what makes the next migration possible: a **re-wrap job** (`POST /v1/rewrap/jobs`) moves many envelopes to the newest version or to another key inside the daemon, without the plaintext ever leaving.

## Key hierarchy and tenants

Keys are encrypted under their **tenant's key-encryption key**, which is encrypted under the vault's **root key**. Each level rotates without downtime (`POST /v1/tenants/{name}/rotate`, `POST /v1/sys/root/rotate`) while a background job re-wraps what lies below. Shredding a tenant (`POST /v1/tenants/{name}/shred`) destroys every key under it at once.

Tenants keep organisations apart in every key, query and audit record. Aegis Cloud gives each organisation its own tenant and a token scoped to it, so Core refuses one organisation's access to another's keys even if the cloud were wrong.

## Seal and unseal

An Aegis Core daemon starts **sealed**: it holds no key that can open the vault. An administrator unseals it with the vault's passphrase, or officers each hand in a Shamir share until the threshold is met (`POST /v1/sys/unseal`, progress at `GET /v1/sys/unseal`). Sealing (`POST /v1/sys/seal`) drops the open vault from memory. While the vault is open, its keys live in locked, guard-paged memory, and core dumps are off.

Changing the unlock without touching the stored keys: `POST /v1/sys/rekey` (new passphrase, or new shares and threshold). Keeping the root key in an HSM or TPM, and unsealing automatically from one, are (Planned).

## Backups

`POST /v1/sys/backup` returns the whole vault as a backup file; `POST /v1/sys/backup/snapshot` keeps a verified copy in the daemon's backup directory. A backup holds every value still encrypted and opens only under the vault's own root key. A restore checks the whole audit chain, and a daemon refuses to unseal a vault that was rolled back to an older copy of itself.

Next: [Audit chain](https://docs.qblackbit.com/concepts/audit.md).
