Skip to main content

KMS API

The following explains how to use the KakaoCloud Key Management Service (KMS) API.

info

This guide documents the existing KMS API. For new KMS API integrations on KakaoCloud Public Cloud, use the endpoint and request/response schema provided in the OpenAPI documentation. The OpenAPI may differ from this guide in available API scope and endpoint.

Key information​

IAM role management​

KMS follows KakaoCloud’s IAM role-based access control (RBAC). It verifies the user’s token within a project, and API permissions are granted according to the assigned role.

Project roles​

RoleProject AdminProject MemberProject ReaderKMS ManagerKMS UserKMS Viewer
Data key creation✓✓✓✓
Data encryption✓✓✓✓
Data decryption✓✓✓✓
Data signature generation✓✓✓✓
Data signature verification✓✓✓✓
HMAC creation✓✓✓✓
HMAC verification✓✓✓✓

Keys​

The following are APIs related to keys.

Generate data key​

Generates a new data key using the specified KMS key. This is available only when the default version of the key is in the Active state.
A new data key is generated with each request.

caution
  • A data key consists of ciphertext and KMS key information in the format KMS prefix + ciphertext.
  • The KMS prefix uses the kckms:version format. Decryption is processed using the specified key version.
  • The ciphertext must include the correct KMS prefix; otherwise, it cannot be decrypted correctly.
  • Do not remove or modify the returned encrypted data. Keep it exactly as provided.
  • Delete plaintext (the plaintext data key) from memory immediately after encryption. Do not store it permanently.
  • Store ciphertext (the encrypted data key) with the encrypted data in a secure repository, such as a database, and use it only when decryption is required.
Request​
Generate Data Key Request Example
curl --location --request POST 'https://kms.kr-central-2.kakaocloud.com/api/v1/keys/{key_id}/data-key' \
--header 'X-Auth-Token: {x-auth-token}' \
--header 'Content-Type: application/json'
API call​
MethodRequest URL
POSThttps://kms.kr-central-2.kakaocloud.com/api/v1/keys/{key_id}/data-key
Path parameter​
ParameterTypeRequiredDescription
key_idstringYesUnique key ID
Request header​
HeaderTypeRequiredDescription
X-Auth-TokenstringYesUser authentication token
Content-TypestringYesapplication/json
Request body​
Generate Data Key Request Body
This API does not use a request body.
Response​
Generate Data Key Response
{
"code": "string",
"message": "string",
"data": {
"plaintext": "string",
"ciphertext": "string"
},
"requestId": "string"
}
Response elements​
FieldTypeDescription
codestringResponse code for the API request.
messagestringResponse message for the API request.
dataobjectObject containing the data key.
data.plaintextstringBase64-encoded plaintext data key.
Use it immediately for encryption, and delete it from memory immediately after use. Do not store it permanently.
data.ciphertextstringData key encrypted with the KMS key.
Store it with the encrypted data in a secure repository, such as a database, and pass it to the decryption API when decryption is required.
requestIdstringIdentifier of the API request.
Status codes​
CodeResponseDescription
200OKSuccess
400Bad RequestInvalid request
- Check error message and correct the request
401UnauthorizedInvalid or expired authentication token
- Check the X-Auth-Token header
403ForbiddenAuthenticated, but no permission for the requested resource or action
- Verify you are using the correct account or project with the appropriate permissions
404Not FoundResource not found
- Check key_id information
405Method Not AllowedHTTP method is not allowed
- Check the API HTTP method, such as GET or POST
409ConflictRequest conflicts with the current resource state
- Check the error message and correct the request
500Internal Server ErrorInternal server error
- Retry later

Encrypt data​

Encrypts data using a symmetric key intended for encryption and decryption. This is available only when the default version of the key is in the Active state.

caution

The maximum size of data that can be encrypted is 4 KB. Additional Authenticated Data (AAD) can be up to 64 KB.

Request​
Encrypt Data Request Example
curl --location --request POST 'https://kms.kr-central-2.kakaocloud.com/api/v1/keys/{key_id}/encrypt' \
--header 'X-Auth-Token: {x-auth-token}' \
--header 'Content-Type: application/json' \
--data-raw '{
"input": "string",
"aad": "string"
}'
API call​
MethodRequest URL
POSThttps://kms.kr-central-2.kakaocloud.com/api/v1/keys/{key_id}/encrypt
Path parameter​
ParameterTypeRequiredDescription
key_idstringYesUnique key ID
Request header​
HeaderTypeRequiredDescription
X-Auth-TokenstringYesUser authentication token
Content-TypestringYesapplication/json
Request body​
Encrypt Data Request Body
{
"input": "string",
"aad": "string"
}
Request elementTypeRequiredDescription
inputstringYesData to encrypt (up to 4 KB)
aadstringNoAdditional Authenticated Data (up to 64 KB)
Response​
Encrypt Data Response
{
"code": "string",
"message": "string",
"data": {
"ciphertext": "string",
"version": 1
},
"requestId": "string"
}
Response elements​
FieldTypeDescription
codestringResponse code for the API request.
messagestringResponse message for the API request.
dataobjectObject containing the encrypted data.
data.ciphertextstringBase64-encoded ciphertext.
data.versionintegerVersion of the key used for encryption.
requestIdstringIdentifier of the API request.
Status codes​
CodeResponseDescription
200OKSuccess
400Bad RequestInvalid request
- Check error message and correct the request
401UnauthorizedInvalid or expired authentication token
- Check the X-Auth-Token header
403ForbiddenAuthenticated, but no permission for the requested resource or action
- Verify you are using the correct account or project with the appropriate permissions
404Not FoundResource not found
- Check key_id information
405Method Not AllowedHTTP method is not allowed
- Check the API HTTP method, such as GET or POST
409ConflictRequest conflicts with the current resource state
- Check the error message and correct the request
500Internal Server ErrorInternal server error
- Retry later

Decrypt data​

Decrypts encrypted data using a symmetric key intended for encryption and decryption. This is available only when the default version of the key is in the Active or Deactivated state.

Request​
Decrypt Data Request Example
curl --location --request POST 'https://kms.kr-central-2.kakaocloud.com/api/v1/keys/{key_id}/decrypt' \
--header 'X-Auth-Token: {x-auth-token}' \
--header 'Content-Type: application/json' \
--data-raw '{
"ciphertext": "string",
"aad": "string"
}'
API call​
MethodRequest URL
POSThttps://kms.kr-central-2.kakaocloud.com/api/v1/keys/{key_id}/decrypt
Path parameter​
ParameterTypeRequiredDescription
key_idstringYesUnique key ID
Request header​
HeaderTypeRequiredDescription
X-Auth-TokenstringYesUser authentication token
Content-TypestringYesapplication/json
Request body​
Decrypt Data Request Body
{
"ciphertext": "string",
"aad": "string"
}
Request elementTypeRequiredDescription
ciphertextstringYesEncrypted data
aadstringNoAdditional Authenticated Data (AAD)
Response​
Decrypt Data Response
{
"code": "string",
"message": "string",
"data": {
"plaintext": "string"
},
"requestId": "string"
}
Response elements​
FieldTypeDescription
codestringResponse code for the API request.
messagestringResponse message for the API request.
dataobjectObject containing the decrypted data.
data.plaintextstringDecrypted plaintext string.
requestIdstringIdentifier of the API request.
Status codes​
CodeResponseDescription
200OKSuccess
400Bad RequestInvalid request
- Check error message and correct the request
401UnauthorizedInvalid or expired authentication token
- Check the X-Auth-Token header
403ForbiddenAuthenticated, but no permission for the requested resource or action
- Verify you are using the correct account or project with the appropriate permissions
404Not FoundResource not found
- Check key_id information
405Method Not AllowedHTTP method is not allowed
- Check the API HTTP method, such as GET or POST
409ConflictRequest conflicts with the current resource state
- Check the error message and correct the request
500Internal Server ErrorInternal server error
- Retry later

Generate data signature​

Signs data using an asymmetric key intended for digital signing and verification. This is available only when the default version of the key is in the Active state.

Signing input types and signing algorithms​

messageType​

Specifies the type of signing input.

ValueValue for contentKMS processing
RAW (default)Original data (Base64-encoded string, up to 4 KB)Computes a hash with the hash algorithm of signingAlgorithm, then signs it
DIGESTPrecomputed hash (Base64-encoded string)Signs the input as is without hashing it again

Use DIGEST when the original data exceeds 4 KB after Base64 encoding, when the original data must not be sent to KMS, or when you need to construct the signing target yourself, as with OpenPGP.

signingAlgorithm​

Specifies the signing scheme and hash algorithm. Any value that matches the key algorithm can be used with either RAW or DIGEST.
A hash entered for DIGEST must be computed with the hash algorithm in the table below. A hash of a different length is rejected.

ValueKey algorithmHash algorithmDescription
RSASSA_PSS_SHA_256RSASHA-256- Default signing algorithm for RSA keys
- MGF1 SHA-256, with the maximum salt length allowed by the key size
RSASSA_PKCS1_V1_5_SHA_256RSASHA-256- PKCS#1 v1.5 signature
- Compatible with external tools that require PKCS#1 v1.5 signatures, such as OpenPGP and JWS RS256
ECDSA_SHA_256ECDSASHA-256- Default signing algorithm for ECDSA keys
- Signature value in ASN.1 DER format
  • If signingAlgorithm is omitted, the default signing algorithm of the key is used regardless of messageType: RSASSA_PSS_SHA_256 for RSA keys and ECDSA_SHA_256 for ECDSA keys.
caution
  • For DIGEST, always enter a hash computed with the hash algorithm of signingAlgorithm. If you enter an arbitrary value that is not a hash, the security of the signature is not guaranteed.
  • If you send a hash without messageType (or with RAW), KMS hashes it again, so verification fails in external tools that assume the hash is applied only once.
  • KMS does not check which original data an input hash came from. We recommend restricting who can use the signing key through access control.
Request​
Sign Data Request Example
curl --location --request POST 'https://kms.kr-central-2.kakaocloud.com/api/v1/keys/{key_id}/sign' \
--header 'X-Auth-Token: {x-auth-token}' \
--header 'Content-Type: application/json' \
--data-raw '{
"content": "string",
"messageType": "string",
"signingAlgorithm": "string"
}'
API call​
MethodRequest URL
POSThttps://kms.kr-central-2.kakaocloud.com/api/v1/keys/{key_id}/sign
Path parameter​
ParameterTypeRequiredDescription
key_idstringYesUnique key ID
Request header​
HeaderTypeRequiredDescription
X-Auth-TokenstringYesUser authentication token
Content-TypestringYesapplication/json
Request body​
Sign Data Request Body
{
"content": "string",
"messageType": "string",
"signingAlgorithm": "string"
}
Request elementTypeRequiredDescription
contentstringYesRAW: Original data to be signed (Base64-encoded string, up to 4 KB)
DIGEST: Hash computed with the hash algorithm of signingAlgorithm (Base64-encoded string)
messageTypestringNoRAW (default) or DIGEST
signingAlgorithmstringNoSigning algorithm. If omitted, the default signing algorithm of the key is used
Response​
Sign Data Response
{
"code": "string",
"message": "string",
"data": {
"signature": "string",
"signingAlgorithm": "string"
},
"requestId": "string"
}
Response elements​
FieldTypeDescription
codestringResponse code for the API request.
messagestringResponse message for the API request.
dataobjectObject containing the signed data.
data.signaturestringThe generated signature value.
data.signingAlgorithmstringThe signing algorithm applied to the signature. If signingAlgorithm is omitted, the default signing algorithm of the key is returned.
requestIdstringIdentifier of the API request.
Status codes​
CodeResponseDescription
200OKSuccess
400Bad RequestInvalid request
- Check error message and correct the request
- messageType or signingAlgorithm is invalid or does not match the key algorithm, or the DIGEST hash length is incorrect
401UnauthorizedInvalid or expired authentication token
- Check the X-Auth-Token header
403ForbiddenAuthenticated, but no permission for the requested resource or action
- Verify you are using the correct account or project with the appropriate permissions
404Not FoundResource not found
- Check key_id information
405Method Not AllowedHTTP method is not allowed
- Check the API HTTP method, such as GET or POST
409ConflictRequest conflicts with the current resource state
- Check the error message and correct the request
500Internal Server ErrorInternal server error
- Retry later
Error codes​
Status codeError codeResponseDescription
4001000Invalid messageType: {input value}messageType is a value other than RAW or DIGEST
4001000Invalid signingAlgorithm: {input value}An undefined signingAlgorithm value is entered (case-sensitive)
4001000Invalid digest lengthmessageType is DIGEST, but the length of content differs from the hash output length of signingAlgorithm (SHA-256: 32 bytes)
4004102Key not supportedA signingAlgorithm that does not match the key algorithm is specified (for example, ECDSA_SHA_256 for an RSA key)

Verify data signature​

Verifies signed data using an asymmetric key intended for digital signing and verification. This is available only when the default version of the key is in the Active or Deactivated state.

caution

Specify the same signingAlgorithm for verification as you used for signing. If the values differ, false is returned even if the signature is valid.

info

You can specify a different messageType for verification than you used for signing. For example, you can verify data signed with RAW by using the hash of the original data. In this case, enter the hash in input and set messageType to DIGEST.

Request​
Verify Signature Request Example
curl --location --request POST 'https://kms.kr-central-2.kakaocloud.com/api/v1/keys/{key_id}/sign/verify' \
--header 'X-Auth-Token: {x-auth-token}' \
--header 'Content-Type: application/json' \
--data-raw '{
"input": "string",
"output": "string",
"messageType": "string",
"signingAlgorithm": "string"
}'
API call​
MethodRequest URL
POSThttps://kms.kr-central-2.kakaocloud.com/api/v1/keys/{key_id}/sign/verify
Path parameter​
ParameterTypeRequiredDescription
key_idstringYesUnique key ID
Request header​
HeaderTypeRequiredDescription
X-Auth-TokenstringYesUser authentication token
Content-TypestringYesapplication/json
Request body​
Verify Signature Request Body
{
"input": "string",
"output": "string",
"messageType": "string",
"signingAlgorithm": "string"
}
Request elementTypeRequiredDescription
inputstringYesData to verify
RAW: Original data (Base64-encoded string)
DIGEST: Hash (Base64-encoded string)
outputstringYesdata.signature value from the signing API response
messageTypestringNoType of the value entered in input
RAW (default) or DIGEST
signingAlgorithmstringNoSame value used for signing. If omitted, the default signing algorithm of the key is used
Response​
Verify Signature Response
{
"code": "string",
"message": "string",
"data": true,
"requestId": "string"
}
Response elements​
FieldTypeDescription
codestringResponse code for the API request.
messagestringResponse message for the API request.
databooleanResult of signature verification
true: success, false: failure
requestIdstringIdentifier of the API request.
Status codes​
CodeResponseDescription
200OKSuccess
400Bad RequestInvalid request
- Check error message and correct the request
- messageType or signingAlgorithm is invalid or does not match the key algorithm, or the DIGEST hash length is incorrect
401UnauthorizedInvalid or expired authentication token
- Check the X-Auth-Token header
403ForbiddenAuthenticated, but no permission for the requested resource or action
- Verify you are using the correct account or project with the appropriate permissions
404Not FoundResource not found
- Check key_id information
405Method Not AllowedHTTP method is not allowed
- Check the API HTTP method, such as GET or POST
409ConflictRequest conflicts with the current resource state
- Check the error message and correct the request
500Internal Server ErrorInternal server error
- Retry later
Error codes​
Status codeError codeResponseDescription
4001000Invalid messageType: {input value}messageType is a value other than RAW or DIGEST
4001000Invalid signingAlgorithm: {input value}An undefined signingAlgorithm value is entered (case-sensitive)
4001000Invalid digest lengthmessageType is DIGEST, but the length of input differs from the hash output length of signingAlgorithm (SHA-256: 32 bytes)
4004102Key not supportedA signingAlgorithm that does not match the key algorithm is specified (for example, ECDSA_SHA_256 for an RSA key)

Create HMAC​

Generates an HMAC using a symmetric key intended for MAC signing and verification. This is available only when the default version of the key is in the Active state.

caution

The original data used for HMAC generation must be Base64-encoded and cannot exceed 4 KB.

Request​
Create HMAC Request Example
curl --location --request POST 'https://kms.kr-central-2.kakaocloud.com/api/v1/keys/{key_id}/hmac' \
--header 'X-Auth-Token: {x-auth-token}' \
--header 'Content-Type: application/json' \
--data-raw '{
"content": "string"
}'
API call​
MethodRequest URL
POSThttps://kms.kr-central-2.kakaocloud.com/api/v1/keys/{key_id}/hmac
Path parameter​
ParameterTypeRequiredDescription
key_idstringYesUnique key ID
Request header​
HeaderTypeRequiredDescription
X-Auth-TokenstringYesUser authentication token
Content-TypestringYesapplication/json
Request body​
Create HMAC Request Body
{
"content": "string"
}
Request elementTypeRequiredDescription
contentstringYesOriginal data for HMAC generation (Base64-encoded string), up to 4 KB
Response​
Create HMAC Response
{
"code": "string",
"message": "string",
"data": {
"hmac": "string"
},
"requestId": "string"
}
Response elements​
FieldTypeDescription
codestringResponse code for the API request.
messagestringResponse message for the API request.
dataobjectObject containing the HMAC data.
data.hmacstringThe generated HMAC authentication code.
requestIdstringIdentifier of the API request.
Status codes​
CodeResponseDescription
200OKSuccess
400Bad RequestInvalid request
- Check error message and correct the request
401UnauthorizedInvalid or expired authentication token
- Check the X-Auth-Token header
403ForbiddenAuthenticated, but no permission for the requested resource or action
- Verify you are using the correct account or project with the appropriate permissions
404Not FoundResource not found
- Check key_id information
405Method Not AllowedHTTP method is not allowed
- Check the API HTTP method, such as GET or POST
409ConflictRequest conflicts with the current resource state
- Check the error message and correct the request
500Internal Server ErrorInternal server error
- Retry later

Verify HMAC​

Verifies an HMAC code generated with a symmetric key intended for MAC signing and verification. This is available only when the default version of the key is in the Active or Deactivated state.

Request​
Verify HMAC Request Example
curl --location --request POST 'https://kms.kr-central-2.kakaocloud.com/api/v1/keys/{key_id}/hmac/verify' \
--header 'X-Auth-Token: {x-auth-token}' \
--header 'Content-Type: application/json' \
--data-raw '{
"input": "string",
"output": "string"
}'
API call​
MethodRequest URL
POSThttps://kms.kr-central-2.kakaocloud.com/api/v1/keys/{key_id}/hmac/verify
Path parameter​
ParameterTypeRequiredDescription
key_idstringYesUnique key ID
Request header​
HeaderTypeRequiredDescription
X-Auth-TokenstringYesUser authentication token
Content-TypestringYesapplication/json
Request body​
Verify HMAC Request Body
{
"input": "string",
"output": "string"
}
Request elementTypeRequiredDescription
inputstringYesOriginal data to verify the HMAC (Base64-encoded string)
outputstringYesHMAC authentication code generated from the input with the specified key (Base64-encoded string)
Response​
Verify HMAC Response
{
"code": "string",
"message": "string",
"data": true,
"requestId": "string"
}
Response elements​
FieldTypeDescription
codestringResponse code for the API request.
messagestringResponse message for the API request.
databooleanResult of HMAC verification
true: verification success, false: verification failure
requestIdstringIdentifier of the API request.
Status codes​
CodeResponseDescription
200OKSuccess
400Bad RequestInvalid request
- Check error message and correct the request
401UnauthorizedInvalid or expired authentication token
- Check the X-Auth-Token header
403ForbiddenAuthenticated, but no permission for the requested resource or action
- Verify you are using the correct account or project with the appropriate permissions
404Not FoundResource not found
- Check key_id information
405Method Not AllowedHTTP method is not allowed
- Check the API HTTP method, such as GET or POST
409ConflictRequest conflicts with the current resource state
- Check the error message and correct the request
500Internal Server ErrorInternal server error
- Retry later