---
title: "Generate Data Encryption Key"
method: POST
path: "/kms-key/{id}/generate-data-key"
tags: ["crypto"]
---

# Generate Data Encryption Key

`POST /kms-key/{id}/generate-data-key`

## Request

- Base URL: `https://api-ch-gva-2.exoscale.com/v2`
- URL: `https://api-ch-gva-2.exoscale.com/v2/kms-key/{id}/generate-data-key`
- Auth: none declared
- TypeScript: <https://skmtc.dev/exoscale/apis/exoscale-api/docs/kms-key/:id/generate-data-key/post.ts> (a function with typed inputs; its response is checked against the schema)

Generate a Data Encryption Key from a given KMS Key.

## Path parameters

- `id` string, uuid, required

## Request body

- GenerateDataKeyRequest
  - `key-spec` 'AES-256'
  - `bytes-count` integer
  - `encryption-context` string, byte, nullable: Base64-encoded Additional Authenticated Data binding key generation parameters securely to operational scope.

## Response `200`

Data Encryption Key in the clear and in its base64 encoded encrypted format.

- GenerateDataKeyResponse
  - `plaintext` string, byte, required: The Base64-encoded raw symmetric data key payload. Expose only securely during active application setups.
  - `ciphertext` string, byte, required: The identical symmetric data key, returned safely wrapped/encrypted using the designated root parent KMS key.

## Other responses

- `400`: ### Errors Key Not Found: The request was rejected because the specified KMS Key could not be found. Key is Disabled: The request was rejected because the specified KMS key is disabled. Invalid Usage: The request was rejected because the operation is only allowed on symmetric keys with usage "encrypt-decrypt".

## Changes

- **2026-11-06** `63da6f74c845`: 2 warning
  - removed the optional property `errors` from the response with the `400` status
  - removed the optional property `instance` from the response with the `400` status
- **2026-03-16** `e05707a7b346`: 1 info
  - endpoint added

[Operation history](https://skmtc.dev/exoscale/apis/exoscale-api/changes/kms-key/:id/generate-data-key/post.md)

---

[API](https://skmtc.dev/exoscale/apis/exoscale-api.md) - [All operations](https://skmtc.dev/exoscale/apis/exoscale-api/llms.txt) - [OpenAPI document](https://skmtc.dev/exoscale/apis/exoscale-api/revisions/63da6f74c845?raw)
