All Products
Search
Document Center

Key Management Service:GenerateDataKeyWithoutPlaintext

Last Updated:Mar 08, 2024

Generates a random data key, which can be used to encrypt local data.

Usage notes

  • Keys outside Key Management Service (KMS) instances: To perform cryptographic operations, use Alibaba Cloud SDK to call operations.
  • Keys in KMS instances: To perform cryptographic operations, use one of the following methods:

QPS limits

You can call this operation up to 750 times per second per account. If the number of the calls per second exceeds the limit, throttling is triggered. As a result, your business may be affected. We recommend that you take note of the limit when you call this operation.

Description

This operation creates a random data key, encrypts the data key by using a key, and then returns the data key ciphertext. The GenerateDataKeyWithoutPlaintext operation provides exactly the same functionality as the GenerateDataKey operation. The only difference is that the GenerateDataKeyWithoutPlaintext operation does not return the data key plaintext.

The key that you specify in the request of this operation is used only to encrypt the data key and is not involved in the generation of the data key. KMS does not record or store the generated data key.

Note
  • This operation applies to the scenario when you do not need to use the data key to encrypt data immediately. Before you can use the data key to encrypt data, you must call the Decrypt operation to decrypt the data key ciphertext.
    Note
    • This operation is also suitable for a distributed system with different trust levels. For example, a system stores data in different partitions based on a preset trust policy. A module of the system creates different partitions and generates different data keys for each partition. This module is not involved in data production and consumption after it completes the initialization of the control plane. This module is the key provider. When a module on the control plane produces and consumes data, the module obtains the data key ciphertext for each partition. After the module decrypts the data key ciphertext, the module uses the data key plaintext to encrypt or decrypt data and then deletes the data key plaintext from memory. In such a system, the key provider does not need to obtain the data key plaintext. It needs only to have the permissions to call the GenerateDataKeyWithoutPlaintext operation. The data producers or consumers do not need to generate new data keys. They need only to have the permissions to call the Decrypt operation.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

Request parameters

Parameter

Type

Required

Example

Description

Action String Yes GenerateDataKeyWithoutPlaintext

The operation that you want to perform. Set the value to GenerateDataKeyWithoutPlaintext.

KeyId String Yes 1234abcd-12ab-34cd-56ef-12345678****

The ID of the key. The ID must be globally unique. You can also set this parameter to an alias that is bound to the key. For more information, see Alias overview.

KeySpec String No AES_256

The type of the data key. Valid values:

  • AES_256: 256-bit symmetric key
  • AES_128: 128-bit symmetric key
Note We recommend that you use KeySpec or NumberOfBytes to specify the length of a data key. If none of the parameters are specified, KMS generates a 256-bit data key. If both parameters are specified, KMS ignores KeySpec.
NumberOfBytes Integer No 256

The length of the data key.

Valid values: 1 to 1024.

Unit: bytes.

EncryptionContext Map No {"Example":"Example"}

The JSON string that consists of key-value pairs. If you configure this parameter, an equivalent value is required when you call the Decrypt operation. For more information, see EncryptionContext.

Response parameters

Parameter

Type

Example

Description

KeyVersionId String 2ab1a983-7072-4bbc-a582-584b5bd8****

The version ID of the key that is used to encrypt the plaintext. The primary version of the key is used.

KeyId String 599fa825-17de-417e-9554-bb032cc6****

The ID of the key. The ID must be globally unique.

Note If you set KeyId to an alias of the key, the ID of the key to which the alias is bound is returned.
CiphertextBlob String ODZhOWVmZDktM2QxNi00ODk0LWJkNGYtMWZjNDNmM2YyYWJmS7FmDBBQ0BkKsQrtRnidtPwirmDcS0ZuJCU41xxAAWk4Z8qsADfbV0b+i6kQmlvj79dJdGOvtX69Uycs901qOjop4bTS****

The data key ciphertext that is encrypted by using the primary version of the key.

RequestId String 7021b6ec-4be7-4d3c-8a68-1e85d4d515a0

The ID of the request.

Examples

Sample requests

https://[Endpoint]/?Action=GenerateDataKeyWithoutPlaintext
&KeyId=1234abcd-12ab-34cd-56ef-12345678****
&<Common request parameters>

Sample success responses

XML format

HTTP/1.1 200 OK
Content-Type:application/xml

<KMS>
       <RequestId>7021b6ec-4be7-4d3c-8a68-1e85d4d515a0</RequestId>
       <CiphertextBlob>ODZhOWVmZDktM2QxNi00ODk0LWJkNGYtMWZjNDNmM2YyYWJmS7FmDBBQ0BkKsQrtRnidtPwirmDcS0ZuJCU41xxAAWk4Z8qsADfbV0b+i6kQmlvj79dJdGOvtX69Uycs901qOjop4bTS****</CiphertextBlob>
       <KeyId>599fa825-17de-417e-9554-bb032cc6****</KeyId>
       <KeyVersionId>2ab1a983-7072-4bbc-a582-584b5bd8****</KeyVersionId>
</KMS>

JSON format

HTTP/1.1 200 OK
Content-Type:application/json

{
  "RequestId" : "7021b6ec-4be7-4d3c-8a68-1e85d4d515a0",
  "CiphertextBlob" : "ODZhOWVmZDktM2QxNi00ODk0LWJkNGYtMWZjNDNmM2YyYWJmS7FmDBBQ0BkKsQrtRnidtPwirmDcS0ZuJCU41xxAAWk4Z8qsADfbV0b+i6kQmlvj79dJdGOvtX69Uycs901qOjop4bTS****",
  "KeyId" : "599fa825-17de-417e-9554-bb032cc6****",
  "KeyVersionId" : "2ab1a983-7072-4bbc-a582-584b5bd8****"
}

Error codes

HTTP status code

Error code

Error message

Description

400 InvalidParameter The specified parameter is not valid. The specified parameter is invalid.
404 Forbidden.KeyNotFound The specified Key is not found. The specified key does not exist.

For a list of error codes, see Service error codes.