# Encodings

PKCS #8, SPKI, JWK and COSE keys; X.509 certificates and requests; CMS, JWS, JWE and COSE messages. Aegis Core API, `EncodingService`: 16 operations, generated from the OpenAPI document of Aegis Core 0.13.0.

## CMS encrypt

`POST /v1/encoding/cms/encrypt`

CMS `AuthEnvelopedData` to ML-KEM recipients (RFC 9629, RFC 9936).

- Role: `operator` or higher
- gRPC: `/aegis.v1.EncodingService/CmsEncrypt`

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

| Field | Type | Description |
| --- | --- | --- |
| `content` | string (base64) | The content. |
| `recipients` | array of string | Each recipient's ML-KEM public key or certificate (PEM). |

Response `200` (`application/json`): [CmsEncryptResponse](#schema-cmsencryptresponse)

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

## CMS verify

`POST /v1/encoding/cms/verify`

Verifies a CMS `SignedData`.

- Role: `operator` or higher
- gRPC: `/aegis.v1.EncodingService/CmsVerify`

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

| Field | Type | Description |
| --- | --- | --- |
| `certificates` | array of string | Certificates (PEM) that may identify the signers. |
| `cms` | string (base64) | `ContentInfo` holding `SignedData`, DER. |
| `content` | string (base64), nullable | The content, for detached signed data. |

Response `200` (`application/json`): [CmsVerifyResponse](#schema-cmsverifyresponse)

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

## COSE verify

`POST /v1/encoding/cose/verify`

Verifies a `COSE_Sign1` under a `COSE_Key`.

- Role: `operator` or higher
- gRPC: `/aegis.v1.EncodingService/CoseVerify`

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

| Field | Type | Description |
| --- | --- | --- |
| `aad` | string (base64) | External associated data. |
| `cose` | string (base64) | The tagged `COSE_Sign1`. |
| `key` | string (base64) | The signer's `COSE_Key`. |

Response `200` (`application/json`): [CoseVerifyResponse](#schema-coseverifyresponse)

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

## JWE encrypt

`POST /v1/encoding/jwe/encrypt`

A compact JWE (`A256GCM`) to a recipient's JWK: `RSA-OAEP-256` or `ECDH-ES`.

- Role: `operator` or higher
- gRPC: `/aegis.v1.EncodingService/JweEncrypt`

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

| Field | Type | Description |
| --- | --- | --- |
| `algorithm` | string, nullable | The algorithm, when the JWK fits several. |
| `jwk` | string | The recipient's public JWK, as JSON text. |
| `plaintext` | string (base64) | The plaintext. |

Response `200` (`application/json`): [JweEncryptResponse](#schema-jweencryptresponse)

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

## JWS verify

`POST /v1/encoding/jws/verify`

Verifies a compact JWS under a JWK.

- Role: `operator` or higher
- gRPC: `/aegis.v1.EncodingService/JwsVerify`

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

| Field | Type | Description |
| --- | --- | --- |
| `algorithm` | string, nullable | The algorithm, when the JWK fits several. |
| `jwk` | string | The signer's public JWK, as JSON text. |
| `jws` | string | The compact serialisation. |

Response `200` (`application/json`): [JwsVerifyResponse](#schema-jwsverifyresponse)

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

## Convert key

`POST /v1/encoding/keys/convert`

Reads a key in any supported encoding, checks it and writes it in another. Nothing is stored.

- Role: `operator` or higher
- gRPC: `/aegis.v1.EncodingService/ConvertKey`

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

| Field | Type | Description |
| --- | --- | --- |
| `algorithm` | string, nullable | The algorithm, when the input fits several (ECDH or ECDSA, the RSA sets). |
| `form` | string, nullable | The PKCS #8 form, for `pkcs8`. |
| `input` | string | PEM (PUBLIC KEY or PRIVATE KEY), a JWK, or a `COSE_Key` in base64. |
| `to` | string | `spki`, `pkcs8`, `jwk` or `cose-key`. |

Response `200` (`application/json`): [ConvertKeyResponse](#schema-convertkeyresponse)

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

## X.509 verify chain

`POST /v1/encoding/x509/verify`

Verifies a certificate chain, leaf first, up to one of the anchors.

- Role: `operator` or higher
- gRPC: `/aegis.v1.EncodingService/X509VerifyChain`

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

| Field | Type | Description |
| --- | --- | --- |
| `anchors` | array of string | The trust anchors (PEM). |
| `at` | integer (int64), nullable | The time to verify at, in seconds since the Unix epoch; now by default. |
| `chain` | array of string | The certificates (PEM), leaf first. |

Response `200` (`application/json`): [X509VerifyChainResponse](#schema-x509verifychainresponse)

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

## Issue certificate

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

A certificate signed by a vault key: self-signed, or issued under the key's own certificate for another key (from a checked request or a public key).

- Role: `admin` or higher
- gRPC: `/aegis.v1.EncodingService/IssueCertificate`

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

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

| Field | Type | Description |
| --- | --- | --- |
| `ca` | boolean | Whether the certificate is an authority's. |
| `days` | integer (int64) | Days of validity from now, 1 to 36525. |
| `issuer_certificate` | string, nullable | The issuer's certificate (PEM); absent for a self-signed certificate. |
| `path_len` | integer (int64), nullable | Its path length constraint. |
| `request` | string, nullable | The subject's PKCS #10 request (PEM), checked before anything is signed. |
| `subject` | string, nullable | The subject (RFC 4514); taken from `request` when that is given. |
| `subject_public_key` | string, nullable | The subject's public key (PEM), when no request is given. |

Response `200` (`application/json`): [IssueCertificateResponse](#schema-issuecertificateresponse)

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

## CMS decrypt

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

Decrypts a CMS `AuthEnvelopedData` with a vault ML-KEM key.

- Role: `operator` or higher
- gRPC: `/aegis.v1.EncodingService/CmsDecrypt`

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

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

| Field | Type | Description |
| --- | --- | --- |
| `cms` | string (base64) | `ContentInfo` holding `AuthEnvelopedData`, DER. |

Response `200` (`application/json`): [CmsDecryptResponse](#schema-cmsdecryptresponse)

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

## CMS sign

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

CMS `SignedData` over a content, signed by a vault key.

- Role: `operator` or higher
- gRPC: `/aegis.v1.EncodingService/CmsSign`

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

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

| Field | Type | Description |
| --- | --- | --- |
| `certificate` | string, nullable | The signer's certificate (PEM), included and naming the signer; without one the signer is named by its key identifier. |
| `content` | string (base64) | The content. |
| `detached` | boolean | Leave the content out. |

Response `200` (`application/json`): [CmsSignResponse](#schema-cmssignresponse)

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

## COSE sign

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

A tagged `COSE_Sign1` signed by a vault key.

- Role: `operator` or higher
- gRPC: `/aegis.v1.EncodingService/CoseSign`

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

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

| Field | Type | Description |
| --- | --- | --- |
| `aad` | string (base64) | External associated data. |
| `kid` | string (base64), nullable | A key identifier for the header. |
| `payload` | string (base64) | The payload. |

Response `200` (`application/json`): [CoseSignResponse](#schema-cosesignresponse)

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

## Certification request

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

A PKCS #10 certification request for a signature key, signed by the vault.

- Role: `operator` or higher
- gRPC: `/aegis.v1.EncodingService/CertificationRequest`

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

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

| Field | Type | Description |
| --- | --- | --- |
| `subject` | string | The subject (RFC 4514). |

Response `200` (`application/json`): [CertificationRequestResponse](#schema-certificationrequestresponse)

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

## Export encoded

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

The private key of an exportable key as PKCS #8 (PEM), JWK or `COSE_Key`, through the vault's audited export.

- Role: `admin` or higher
- gRPC: `/aegis.v1.EncodingService/ExportEncoded`

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

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

| Field | Type | Description |
| --- | --- | --- |
| `form` | string, nullable | The PKCS #8 form: `seed`, `expanded`, `both` or `single`; the seed for ML-KEM and ML-DSA by default. |
| `format` | string | `pkcs8`, `jwk` or `cose-key`. |
| `version` | integer (int64), nullable | The version; the newest by default. |
| `with_public` | boolean | Include the public key in the PKCS #8 structure. |

Response `200` (`application/json`): [EncodedKeyResponse](#schema-encodedkeyresponse)

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

## JWE decrypt

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

Decrypts a compact JWE with a vault key-transport or agreement key.

- Role: `operator` or higher
- gRPC: `/aegis.v1.EncodingService/JweDecrypt`

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

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

| Field | Type | Description |
| --- | --- | --- |
| `jwe` | string | The compact serialisation. |

Response `200` (`application/json`): [JweDecryptResponse](#schema-jwedecryptresponse)

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

## JWS sign

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

A compact JWS signed by a vault key.

- Role: `operator` or higher
- gRPC: `/aegis.v1.EncodingService/JwsSign`

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

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

| Field | Type | Description |
| --- | --- | --- |
| `kid` | boolean | Name the key in the header (`kid`). |
| `payload` | string (base64) | The payload. |

Response `200` (`application/json`): [JwsSignResponse](#schema-jwssignresponse)

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

## Encoded public key

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

The public key of a key's newest version as SPKI (PEM), JWK or `COSE_Key` (base64).

- Role: `auditor` or higher
- gRPC: `/aegis.v1.EncodingService/EncodedPublicKey`

| Parameter | In | Type | Description |
| --- | --- | --- | --- |
| `name` | path | string, required |  |
| `format` | query | string | `spki`, `jwk` or `cose-key`. |

Response `200` (`application/json`): [EncodedKeyResponse](#schema-encodedkeyresponse)

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

## Schemas

### CertificationRequestResponse

The certification request.

| Field | Type | Description |
| --- | --- | --- |
| `request` | string | PKCS #10, PEM. |

### CmsDecryptResponse

The decrypted content.

| Field | Type | Description |
| --- | --- | --- |
| `content` | string (base64) | The content. |

### CmsEncryptResponse

The enveloped data.

| Field | Type | Description |
| --- | --- | --- |
| `cms` | string (base64) | `ContentInfo` holding `AuthEnvelopedData`, DER. |

### CmsSignResponse

The signed data.

| Field | Type | Description |
| --- | --- | --- |
| `cms` | string (base64) | `ContentInfo` holding `SignedData`, DER. |

### CmsVerifyResponse

Whether the signed data verified.

| Field | Type | Description |
| --- | --- | --- |
| `content` | string (base64), nullable | The content, when it was encapsulated. |
| `content_type` | string, nullable | The encapsulated content type. |
| `reason` | string, nullable | Why it did not verify. |
| `signers` | array of [CmsSigner](#schema-cmssigner) | Every signer, each verified. |
| `valid` | boolean | Whether every signer verified. |

### ConvertKeyResponse

The converted key.

| Field | Type | Description |
| --- | --- | --- |
| `algorithm` | string | The key's algorithm. |
| `output` | string | The key in the requested encoding. |
| `private` | boolean | Whether the input held a private key. |
| `public_key` | string (base64) | The public key. |

### CoseSignResponse

The signed message.

| Field | Type | Description |
| --- | --- | --- |
| `cose` | string (base64) | The tagged `COSE_Sign1`. |

### CoseVerifyResponse

Whether the message verified.

| Field | Type | Description |
| --- | --- | --- |
| `algorithm` | string, nullable | The key's algorithm. |
| `payload` | string (base64), nullable | The payload. |
| `reason` | string, nullable | Why it did not verify. |
| `valid` | boolean | Whether it verified. |

### EncodedKeyResponse

An encoded key.

| Field | Type | Description |
| --- | --- | --- |
| `algorithm` | string | The key's algorithm. |
| `format` | string | The format asked for. |
| `key` | string | The key: PEM, a JWK as JSON text, or a `COSE_Key` in base64. |

### IssueCertificateResponse

The issued certificate.

| Field | Type | Description |
| --- | --- | --- |
| `certificate` | string | The certificate, PEM. |

### JweDecryptResponse

The decrypted JWE.

| Field | Type | Description |
| --- | --- | --- |
| `plaintext` | string (base64) | The plaintext. |

### JweEncryptResponse

The JWE.

| Field | Type | Description |
| --- | --- | --- |
| `jwe` | string | The compact serialisation. |

### JwsSignResponse

The JWS.

| Field | Type | Description |
| --- | --- | --- |
| `jws` | string | The compact serialisation. |

### JwsVerifyResponse

Whether the JWS verified.

| Field | Type | Description |
| --- | --- | --- |
| `algorithm` | string, nullable | The key's algorithm. |
| `payload` | string (base64), nullable | The payload. |
| `reason` | string, nullable | Why it did not verify. |
| `valid` | boolean | Whether it verified. |

### X509VerifyChainResponse

Whether the chain verified, and what it holds.

| Field | Type | Description |
| --- | --- | --- |
| `algorithms` | array of string | The algorithm of each signature checked, leaf first. |
| `certificates` | array of [X509CertificateInfo](#schema-x509certificateinfo) | The certificates, leaf first, anchor last. |
| `reason` | string, nullable | Why it did not verify. |
| `valid` | boolean | Whether it verified. |

### CmsSigner

One verified signer.

| Field | Type | Description |
| --- | --- | --- |
| `algorithm` | string | The signature algorithm. |
| `certificate` | string, nullable | The signer's certificate (PEM), when one identified the signer. |
| `subject` | string, nullable | The signer certificate's subject, when a certificate identified the signer. |

### X509CertificateInfo

One certificate of a verified chain.

| Field | Type | Description |
| --- | --- | --- |
| `ca` | boolean | Whether the basic constraints say it is an authority. |
| `issuer` | string | The issuer, RFC 4514. |
| `key_algorithms` | array of string | The subject key's algorithm, when Aegis knows it (an ambiguous key names several). |
| `not_after` | integer (int64) | End of validity. |
| `not_before` | integer (int64) | Start of validity, seconds since the Unix epoch. |
| `path_len` | integer (int64), nullable | Its path length constraint. |
| `serial` | string | The serial number, hexadecimal. |
| `signature_oid` | string | The signature algorithm's object identifier. |
| `subject` | string | The subject, RFC 4514. |
