# Keys

Vault keys: create, import, rotate, states and dates, sign, verify, encrypt, decrypt, decapsulate, agree, export. Aegis Core API, `KeyService`: 23 operations, generated from the OpenAPI document of Aegis Core 0.13.0.

## List keys

`GET /v1/keys`

Every key.

- Role: `auditor` or higher
- gRPC: `/aegis.v1.KeyService/ListKeys`

Response `200` (`application/json`): [ListKeysResponse](#schema-listkeysresponse)

Errors: `400` · `401` · `403` · `404` · `409` · `413` · `500` · `503` ([what each means](https://docs.qblackbit.com/api/core/index.md#errors)).

## Create key

`POST /v1/keys`

Creates a key.

- Role: `admin` or higher
- gRPC: `/aegis.v1.KeyService/CreateKey`

Request body, required (`application/json`):

| Field | Type | Description |
| --- | --- | --- |
| `activation` | integer (int64), nullable | Activation date. |
| `algorithm` | string | The algorithm. |
| `deactivation` | integer (int64), nullable | Deactivation date. |
| `description` | string | A description. |
| `export` | string, nullable | `none` (the default), `wrapped` or `plain`, fixed for the key's life. |
| `exportable` | boolean | `true` alone means `plain`. |
| `labels` | map of string to string | Labels. |
| `name` | string | The name. |
| `pre_active` | boolean | Starts pre-active. |
| `tenant` | string, nullable | The tenant whose key-encryption key wraps it. |
| `usages` | array of string | What it may do; every operation of its kind by default. |

Response `201` (`application/json`): [Key](#schema-key)

Errors: `400` · `401` · `403` · `404` · `409` · `413` · `500` · `503` ([what each means](https://docs.qblackbit.com/api/core/index.md#errors)).

## Get key

`GET /v1/keys/{name}`

One key.

- Role: `auditor` or higher
- gRPC: `/aegis.v1.KeyService/GetKey`

| Parameter | In | Type | Description |
| --- | --- | --- | --- |
| `name` | path | string, required |  |

Response `200` (`application/json`): [Key](#schema-key)

Errors: `400` · `401` · `403` · `404` · `409` · `413` · `500` · `503` ([what each means](https://docs.qblackbit.com/api/core/index.md#errors)).

## Agree

`POST /v1/keys/{name}/agree`

The raw key-agreement output with a peer's public value.

- Role: `operator` or higher
- gRPC: `/aegis.v1.KeyService/Agree`

| Parameter | In | Type | Description |
| --- | --- | --- | --- |
| `name` | path | string, required |  |

Request body, required (`application/json`):

| Field | Type | Description |
| --- | --- | --- |
| `peer_public_key` | string (base64) | The peer's public value. |
| `version` | integer (int64) | The version to use. |

Response `200` (`application/json`): [AgreeResponse](#schema-agreeresponse)

Errors: `400` · `401` · `403` · `404` · `409` · `413` · `500` · `503` ([what each means](https://docs.qblackbit.com/api/core/index.md#errors)).

## Set dates

`POST /v1/keys/{name}/dates`

Changes the activation and deactivation dates.

- Role: `admin` or higher
- gRPC: `/aegis.v1.KeyService/SetDates`

| Parameter | In | Type | Description |
| --- | --- | --- | --- |
| `name` | path | string, required |  |

Request body, required (`application/json`):

| Field | Type | Description |
| --- | --- | --- |
| `activation` | integer (int64), nullable | Activation, or absent for none. |
| `deactivation` | integer (int64), nullable | Deactivation, or absent for none. |

Response `200` (`application/json`): [Key](#schema-key)

Errors: `400` · `401` · `403` · `404` · `409` · `413` · `500` · `503` ([what each means](https://docs.qblackbit.com/api/core/index.md#errors)).

## Decapsulate

`POST /v1/keys/{name}/decapsulate`

Recovers a shared secret from a KEM ciphertext.

- Role: `operator` or higher
- gRPC: `/aegis.v1.KeyService/Decapsulate`

| Parameter | In | Type | Description |
| --- | --- | --- | --- |
| `name` | path | string, required |  |

Request body, required (`application/json`):

| Field | Type | Description |
| --- | --- | --- |
| `ciphertext` | string (base64) | The KEM ciphertext. |
| `version` | integer (int64) | The version it was sent to. |

Response `200` (`application/json`): [DecapsulateResponse](#schema-decapsulateresponse)

Errors: `400` · `401` · `403` · `404` · `409` · `413` · `500` · `503` ([what each means](https://docs.qblackbit.com/api/core/index.md#errors)).

## Decrypt

`POST /v1/keys/{name}/decrypt`

Decrypts an envelope.

- Role: `operator` or higher
- gRPC: `/aegis.v1.KeyService/Decrypt`

| Parameter | In | Type | Description |
| --- | --- | --- | --- |
| `name` | path | string, required |  |

Request body, required (`application/json`):

| Field | Type | Description |
| --- | --- | --- |
| `associated_data` | string (base64) | The associated data it is bound to. |
| `envelope` | string (base64) | The envelope. |

Response `200` (`application/json`): [DecryptResponse](#schema-decryptresponse)

Errors: `400` · `401` · `403` · `404` · `409` · `413` · `500` · `503` ([what each means](https://docs.qblackbit.com/api/core/index.md#errors)).

## Schedule deletion

`POST /v1/keys/{name}/delete`

Schedules a deletion after a waiting period.

- Role: `admin` or higher
- gRPC: `/aegis.v1.KeyService/ScheduleDeletion`

| Parameter | In | Type | Description |
| --- | --- | --- | --- |
| `name` | path | string, required |  |

Request body, required (`application/json`):

| Field | Type | Description |
| --- | --- | --- |
| `confirm` | string | The key's name again. |
| `wait_days` | integer (int64) | The waiting period in days. |

Response `200` (`application/json`): [Key](#schema-key)

Errors: `400` · `401` · `403` · `404` · `409` · `413` · `500` · `503` ([what each means](https://docs.qblackbit.com/api/core/index.md#errors)).

## Cancel deletion

`POST /v1/keys/{name}/delete/cancel`

Cancels a scheduled deletion.

- Role: `admin` or higher
- gRPC: `/aegis.v1.KeyService/CancelDeletion`

| Parameter | In | Type | Description |
| --- | --- | --- | --- |
| `name` | path | string, required |  |

Response `200` (`application/json`): [Key](#schema-key)

Errors: `400` · `401` · `403` · `404` · `409` · `413` · `500` · `503` ([what each means](https://docs.qblackbit.com/api/core/index.md#errors)).

## Destroy key

`POST /v1/keys/{name}/destroy`

Crypto-shreds every version now.

- Role: `admin` or higher
- gRPC: `/aegis.v1.KeyService/DestroyKey`

| Parameter | In | Type | Description |
| --- | --- | --- | --- |
| `name` | path | string, required |  |

Request body, required (`application/json`):

| Field | Type | Description |
| --- | --- | --- |
| `confirm` | string | The key's name again. |

Response `200` (`application/json`): [Key](#schema-key)

Errors: `400` · `401` · `403` · `404` · `409` · `413` · `500` · `503` ([what each means](https://docs.qblackbit.com/api/core/index.md#errors)).

## Encrypt

`POST /v1/keys/{name}/encrypt`

Encrypts into a self-describing envelope.

- Role: `operator` or higher
- gRPC: `/aegis.v1.KeyService/Encrypt`

| Parameter | In | Type | Description |
| --- | --- | --- | --- |
| `name` | path | string, required |  |

Request body, required (`application/json`):

| Field | Type | Description |
| --- | --- | --- |
| `associated_data` | string (base64) | Associated data bound to the envelope. |
| `plaintext` | string (base64) | The plaintext. |

Response `200` (`application/json`): [EncryptResponse](#schema-encryptresponse)

Errors: `400` · `401` · `403` · `404` · `409` · `413` · `500` · `503` ([what each means](https://docs.qblackbit.com/api/core/index.md#errors)).

## Export key

`POST /v1/keys/{name}/export`

Exports a version in clear, or wrapped to a recipient with HPKE.

- Role: `admin` or higher
- gRPC: `/aegis.v1.KeyService/ExportKey`

| Parameter | In | Type | Description |
| --- | --- | --- | --- |
| `name` | path | string, required |  |

Request body, required (`application/json`):

| Field | Type | Description |
| --- | --- | --- |
| `to` | [ExportRecipient](#schema-exportrecipient), nullable | Wrap to a recipient instead of exporting in clear. |
| `version` | integer (int64), nullable | The version; the newest by default. |

Response `200` (`application/json`): [ExportKeyResponse](#schema-exportkeyresponse)

Errors: `400` · `401` · `403` · `404` · `409` · `413` · `500` · `503` ([what each means](https://docs.qblackbit.com/api/core/index.md#errors)).

## HPKE open

`POST /v1/keys/{name}/hpke/open`

Opens an HPKE message sealed to a vault HPKE key.

- Role: `operator` or higher
- gRPC: `/aegis.v1.KeyService/HpkeOpen`

| Parameter | In | Type | Description |
| --- | --- | --- | --- |
| `name` | path | string, required |  |

Request body, required (`application/json`):

| Field | Type | Description |
| --- | --- | --- |
| `aad` | string (base64) | HPKE aad. |
| `aead` | string | The HPKE AEAD. |
| `ciphertext` | string (base64) | The ciphertext. |
| `enc` | string (base64) | The encapsulated key. |
| `info` | string (base64) | HPKE info. |
| `kdf` | string | The HPKE KDF. |
| `psk` | string (base64) | A pre-shared key. |
| `psk_id` | string (base64) | Its identifier. |
| `sender_public_key` | string (base64), nullable | The sender's public key (mode auth). |
| `version` | integer (int64) | The version it was sealed to. |

Response `200` (`application/json`): [HpkeOpenResponse](#schema-hpkeopenresponse)

Errors: `400` · `401` · `403` · `404` · `409` · `413` · `500` · `503` ([what each means](https://docs.qblackbit.com/api/core/index.md#errors)).

## Import key

`POST /v1/keys/{name}/import`

Imports a key made elsewhere, after the algorithm's key checks.

- Role: `admin` or higher
- gRPC: `/aegis.v1.KeyService/ImportKey`

| Parameter | In | Type | Description |
| --- | --- | --- | --- |
| `name` | path | string, required |  |

Request body, required (`application/json`):

| Field | Type | Description |
| --- | --- | --- |
| `activation` | integer (int64), nullable | Activation date. |
| `algorithm` | string | The algorithm. |
| `deactivation` | integer (int64), nullable | Deactivation date. |
| `description` | string | A description. |
| `export` | string, nullable | `none`, `wrapped` or `plain`. |
| `exportable` | boolean | `true` alone means `plain`. |
| `labels` | map of string to string | Labels. |
| `loosen_export` | boolean | Allow the export policy asked for, for material from outside (audited). |
| `material` | string (base64), nullable | The material in clear. |
| `name` | string | The name. |
| `pre_active` | boolean | Starts pre-active. |
| `public_key` | string (base64), nullable | The public key, checked against the material. |
| `tenant` | string, nullable | The tenant. |
| `usages` | array of string | What it may do. |
| `wrapped` | [WrappedMaterial](#schema-wrappedmaterial), nullable | Or sealed to an escrow key. |

Response `201` (`application/json`): [Key](#schema-key)

Errors: `400` · `401` · `403` · `404` · `409` · `413` · `500` · `503` ([what each means](https://docs.qblackbit.com/api/core/index.md#errors)).

## Set metadata

`POST /v1/keys/{name}/metadata`

Replaces the description and labels.

- Role: `admin` or higher
- gRPC: `/aegis.v1.KeyService/SetMetadata`

| Parameter | In | Type | Description |
| --- | --- | --- | --- |
| `name` | path | string, required |  |

Request body, required (`application/json`):

| Field | Type | Description |
| --- | --- | --- |
| `description` | string | The description. |
| `labels` | map of string to string | The labels. |

Response `200` (`application/json`): [Key](#schema-key)

Errors: `400` · `401` · `403` · `404` · `409` · `413` · `500` · `503` ([what each means](https://docs.qblackbit.com/api/core/index.md#errors)).

## Public key

`GET /v1/keys/{name}/public`

The current version's public key.

- Role: `auditor` or higher
- gRPC: `/aegis.v1.KeyService/PublicKey`

| Parameter | In | Type | Description |
| --- | --- | --- | --- |
| `name` | path | string, required |  |

Response `200` (`application/json`): [PublicKeyResponse](#schema-publickeyresponse)

Errors: `400` · `401` · `403` · `404` · `409` · `413` · `500` · `503` ([what each means](https://docs.qblackbit.com/api/core/index.md#errors)).

## Receive

`POST /v1/keys/{name}/receive`

Recovers a secret transported (RSA-OAEP) to a key-transport key.

- Role: `operator` or higher
- gRPC: `/aegis.v1.KeyService/Receive`

| Parameter | In | Type | Description |
| --- | --- | --- | --- |
| `name` | path | string, required |  |

Request body, required (`application/json`):

| Field | Type | Description |
| --- | --- | --- |
| `ciphertext` | string (base64) | The ciphertext. |
| `label` | string (base64) | The OAEP label. |
| `version` | integer (int64) | The version it was sent to. |

Response `200` (`application/json`): [ReceiveResponse](#schema-receiveresponse)

Errors: `400` · `401` · `403` · `404` · `409` · `413` · `500` · `503` ([what each means](https://docs.qblackbit.com/api/core/index.md#errors)).

## Rewrap

`POST /v1/keys/{name}/rewrap`

Re-encrypts an envelope under the newest version, or another key, inside the daemon.

- Role: `operator` or higher
- gRPC: `/aegis.v1.KeyService/Rewrap`

| Parameter | In | Type | Description |
| --- | --- | --- | --- |
| `name` | path | string, required |  |

Request body, required (`application/json`):

| Field | Type | Description |
| --- | --- | --- |
| `associated_data` | string (base64) | The associated data it is bound to. |
| `envelope` | string (base64) | The envelope. |
| `to` | string, nullable | Another key to move it to. |

Response `200` (`application/json`): [RewrapResponse](#schema-rewrapresponse)

Errors: `400` · `401` · `403` · `404` · `409` · `413` · `500` · `503` ([what each means](https://docs.qblackbit.com/api/core/index.md#errors)).

## Rotate key

`POST /v1/keys/{name}/rotate`

A new current version.

- Role: `admin` or higher
- gRPC: `/aegis.v1.KeyService/RotateKey`

| Parameter | In | Type | Description |
| --- | --- | --- | --- |
| `name` | path | string, required |  |

Response `200` (`application/json`): [Key](#schema-key)

Errors: `400` · `401` · `403` · `404` · `409` · `413` · `500` · `503` ([what each means](https://docs.qblackbit.com/api/core/index.md#errors)).

## Sign

`POST /v1/keys/{name}/sign`

Signs with the newest version.

- Role: `operator` or higher
- gRPC: `/aegis.v1.KeyService/Sign`

| Parameter | In | Type | Description |
| --- | --- | --- | --- |
| `name` | path | string, required |  |

Request body, required (`application/json`):

| Field | Type | Description |
| --- | --- | --- |
| `context` | string (base64) | The context string (FIPS 204, 205), at most 255 bytes. |
| `deterministic` | boolean | The deterministic variant instead of hedged signing. |
| `envelope` | boolean | Sign into a self-describing envelope (AGS2) instead of a bare signature. |
| `message` | string (base64) | The message. |
| `prehash` | string, nullable | The pre-hash function, for HashML-DSA and HashSLH-DSA. |

Response `200` (`application/json`): [SignResponse](#schema-signresponse)

Errors: `400` · `401` · `403` · `404` · `409` · `413` · `500` · `503` ([what each means](https://docs.qblackbit.com/api/core/index.md#errors)).

## Set state

`POST /v1/keys/{name}/state`

Activates, suspends, resumes, deactivates or marks compromised.

- Role: `admin` or higher
- gRPC: `/aegis.v1.KeyService/SetState`

| Parameter | In | Type | Description |
| --- | --- | --- | --- |
| `name` | path | string, required |  |

Request body, required (`application/json`):

| Field | Type | Description |
| --- | --- | --- |
| `state` | string | `active`, `suspended`, `deactivated` or `compromised`. |

Response `200` (`application/json`): [Key](#schema-key)

Errors: `400` · `401` · `403` · `404` · `409` · `413` · `500` · `503` ([what each means](https://docs.qblackbit.com/api/core/index.md#errors)).

## Verify

`POST /v1/keys/{name}/verify`

Verifies a signature, bare with its version or in its envelope.

- Role: `auditor` or higher
- gRPC: `/aegis.v1.KeyService/Verify`

| Parameter | In | Type | Description |
| --- | --- | --- | --- |
| `name` | path | string, required |  |

Request body, required (`application/json`):

| Field | Type | Description |
| --- | --- | --- |
| `context` | string (base64) | The context string. |
| `envelope` | string (base64), nullable | Or the signature envelope, which names the version. |
| `message` | string (base64) | The message. |
| `prehash` | string, nullable | The pre-hash function expected; pure when absent. An envelope must name exactly this form. |
| `signature` | string (base64), nullable | The bare signature. |
| `version` | integer (int64), nullable | The version that signed (with `signature`). |

Response `200` (`application/json`): [VerifyResponse](#schema-verifyresponse)

Errors: `400` · `401` · `403` · `404` · `409` · `413` · `500` · `503` ([what each means](https://docs.qblackbit.com/api/core/index.md#errors)).

## Import version

`POST /v1/keys/{name}/versions`

Imports a further version.

- Role: `admin` or higher
- gRPC: `/aegis.v1.KeyService/ImportVersion`

| Parameter | In | Type | Description |
| --- | --- | --- | --- |
| `name` | path | string, required |  |

Request body, required (`application/json`):

| Field | Type | Description |
| --- | --- | --- |
| `loosen_export` | boolean | Allow it into an exportable key, for material from outside (audited). |
| `material` | string (base64), nullable | The material in clear. |
| `public_key` | string (base64), nullable | The public key, checked against the material. |
| `wrapped` | [WrappedMaterial](#schema-wrappedmaterial), nullable | Or sealed to an escrow key. |

Response `200` (`application/json`): [Key](#schema-key)

Errors: `400` · `401` · `403` · `404` · `409` · `413` · `500` · `503` ([what each means](https://docs.qblackbit.com/api/core/index.md#errors)).

## Schemas

### AgreeResponse

The raw shared secret.

| Field | Type | Description |
| --- | --- | --- |
| `caution` | string, nullable | The caution of a retired or broken algorithm. |
| `shared_secret` | string (base64) | The shared secret. |

### DecapsulateResponse

The shared secret.

| Field | Type | Description |
| --- | --- | --- |
| `caution` | string, nullable | The caution of a retired or broken algorithm. |
| `shared_secret` | string (base64) | The shared secret. |

### DecryptResponse

The plaintext.

| Field | Type | Description |
| --- | --- | --- |
| `caution` | string, nullable | The caution of a retired or broken algorithm. |
| `plaintext` | string (base64) | The plaintext. |

### EncryptResponse

The envelope.

| Field | Type | Description |
| --- | --- | --- |
| `caution` | string, nullable | The caution of a retired or broken algorithm. |
| `envelope` | string (base64) | The self-describing envelope (AGV2). |

### ExportKeyResponse

The exported material: in clear, or wrapped.

| Field | Type | Description |
| --- | --- | --- |
| `aead` | string, nullable | The HPKE AEAD. |
| `algorithm` | string, nullable | The key's algorithm. |
| `caution` | string, nullable | The caution of a retired or broken algorithm. |
| `ciphertext` | string (base64), nullable | The ciphertext. |
| `enc` | string (base64), nullable | The encapsulated key. |
| `export` | string, nullable | The source's export policy. |
| `info` | string (base64), nullable | The HPKE info, which binds the source's terms. |
| `kdf` | string, nullable | The HPKE KDF. |
| `kem` | string, nullable | The HPKE KEM. |
| `material` | string (base64), nullable | The material in clear. |
| `state` | string, nullable | The source's state. |
| `usages` | array of string | The source's usages. |
| `version` | integer (int64), nullable | The version wrapped. |

### ExportRecipient

The recipient of a wrapped export.

| Field | Type | Description |
| --- | --- | --- |
| `aead` | string, nullable | The HPKE AEAD. |
| `kdf` | string, nullable | The HPKE KDF. |
| `kem` | string, nullable | Or an HPKE KEM. |
| `key` | string, nullable | A vault escrow key. |
| `public_key` | string (base64), nullable | And a public key from outside. |

### HpkeOpenResponse

The plaintext.

| Field | Type | Description |
| --- | --- | --- |
| `caution` | string, nullable | The caution of a retired or broken algorithm. |
| `plaintext` | string (base64) | The plaintext. |

### Key

A key and its versions.

| Field | Type | Description |
| --- | --- | --- |
| `activation` | integer (int64), nullable | Activation date, in seconds since the Unix epoch. |
| `algorithm` | string | The algorithm. |
| `caution` | string, nullable | The caution of a retired or broken algorithm. |
| `created` | integer (int64) | When it was created. |
| `current_version` | integer (int64) | The newest version. |
| `deactivation` | integer (int64), nullable | Deactivation date. |
| `deletion_due` | integer (int64), nullable | When a scheduled deletion falls due. |
| `description` | string | A description, at most 500 characters. |
| `export` | string | `none`, `wrapped` or `plain`. |
| `exportable` | boolean | Whether it may leave in clear. |
| `kind` | string | The algorithm's kind. |
| `labels` | map of string to string | Labels, at most 16. |
| `maturity` | string | The algorithm's maturity. |
| `name` | string | The name. |
| `origin` | string | `generated` or `imported`. |
| `qualified` | string | The name as the vault stores it: `tenant/name` for a tenant's key, the plain name for the default tenant's. |
| `revision` | string | The specification revision it was made under. |
| `state` | string | The state now, with its dates applied. |
| `tenant` | string | The tenant whose key-encryption key wraps it. |
| `updated` | integer (int64) | When it last changed. |
| `usages` | array of string | What the key may do. |
| `versions` | array of [KeyVersion](#schema-keyversion) | Every version. |

### ListKeysResponse

Every key.

| Field | Type | Description |
| --- | --- | --- |
| `keys` | array of [Key](#schema-key) | The keys. |

### PublicKeyResponse

A public key.

| Field | Type | Description |
| --- | --- | --- |
| `public_key` | string (base64) | Its public key. |
| `version` | integer (int64) | The current version. |

### ReceiveResponse

The secret.

| Field | Type | Description |
| --- | --- | --- |
| `caution` | string, nullable | The caution of a retired or broken algorithm. |
| `plaintext` | string (base64) | The secret. |

### RewrapResponse

The re-wrapped envelope.

| Field | Type | Description |
| --- | --- | --- |
| `envelope` | string (base64) | The envelope, in the newest format. |

### SignResponse

A signature.

| Field | Type | Description |
| --- | --- | --- |
| `algorithm` | string | The algorithm. |
| `caution` | string, nullable | The caution of a retired or broken algorithm. |
| `envelope` | string (base64), nullable | The signature envelope (AGS2), when asked for: its signature covers the envelope's signing input, which holds every field of its header. |
| `signature` | string (base64), nullable | The bare signature, unless an envelope was asked for. |
| `version` | integer (int64) | The version that signed. |

### VerifyResponse

Whether it verifies.

| Field | Type | Description |
| --- | --- | --- |
| `caution` | string, nullable | The caution of a retired or broken algorithm. |
| `valid` | boolean | Whether the signature is valid. |

### WrappedMaterial

Material sealed to a vault escrow key for import.

| Field | Type | Description |
| --- | --- | --- |
| `aead` | string, nullable | The HPKE AEAD. |
| `ciphertext` | string (base64) | The ciphertext. |
| `enc` | string (base64) | The encapsulated key. |
| `kdf` | string, nullable | The HPKE KDF. |
| `key` | string | The escrow key. |
| `source` | [WrappedSource](#schema-wrappedsource), nullable | For a wrapped export: the terms its `info` names. |
| `version` | integer (int64) | Its version. |

### KeyVersion

One version of a key.

| Field | Type | Description |
| --- | --- | --- |
| `created` | integer (int64) | When it was made. |
| `destroyed` | boolean | Whether its material is erased. |
| `number` | integer (int64) | Its number. |
| `origin` | string | `generated` or `imported`. |
| `provider` | string | The provider that generated or checked it. |
| `public_key` | string (base64), nullable | Its public key, for an asymmetric key. |
| `software` | string | The Aegis release that made it. |

### WrappedSource

The terms a wrapped export declared.

| Field | Type | Description |
| --- | --- | --- |
| `export` | string | Its export policy. |
| `key` | string | The exported key. |
| `state` | string | Its state. |
| `usages` | array of string | Its usages. |
| `version` | integer (int64) | Its version. |
