Skip to Content
ZITADEL Docs
APIsCore ResourcesV2Action

Add Public Key

Adds a public key to the target for payload encryption. The public key is used to encrypt the payload sent to the target when the payload type is set to PAYLOAD_TYPE_JWE. The public key must be in PEM format and be either an RSA or an EC key. On a successful addition, a key ID is returned which can not only be used to manage the key (activate, remove), but also will be used as the kid header in the JWE token sent to the target to indicate which key was used for encryption. Note that newly added keys are inactive by default. You must activate the key to use it for payload encryption. Providing an optional expiration date allows you to set a validity period for the key. After the expiration date, the key will be automatically deactivated and no longer used for payload encryption. Be sure to activate a new key before the current active key expires to avoid interruptions in your target executions. You can have multiple inactive keys for rotation purposes, but only one active key at a time.

Required permission:

  • action.target.write
POST
/v2/actions/targets/{target_id}/publickeys

Path Parameters

target_id*target_id

The unique identifier of the target to add the public key to.

Request Body

application/json
  1. body
publicKey*public_key

The public key in PEM format. It must be either an RSA or an EC public key.

Formatbyte
expirationDate?|

Optional expiration date of the public key. After the expiration date, the key will be automatically deactivated and no longer used for payload encryption. Be sure to activate a new key before the current active key expires to avoid interruptions. If not set, the key will not expire.

Response Body

Success

application/json
  1. response
keyId?key_id

The KeyID is the unique identifier of the newly added public key. The ID is also used a kid in the JWT header for payload encryption. This allows the target to identify the correct key to use for decryption.

creationDate?creation_date

CreationDate represents the timestamp of the public key addition.

Formatdate-time
Example Request
curl -X POST 'https://example.com/v2/actions/targets/string/publickeys' \  -H 'Content-Type: application/json' \  -d '{  "publicKey": "string"}'
Example Response200
{  "keyId": "string",  "creationDate": "2023-01-15T01:30:15.01Z"}

Was this page helpful?