Skip to content

/AWS1/CL_KMS=>GENERATERANDOM()

About GenerateRandom

Returns a random byte string that is cryptographically secure.

You must use the NumberOfBytes parameter to specify the length of the random byte string. There is no default value for string length.

By default, the random byte string is generated in KMS. To generate the byte string in the CloudHSM cluster associated with an CloudHSM key store, use the CustomKeyStoreId parameter.

GenerateRandom also supports Amazon Web Services Nitro Enclaves, which provide an isolated compute environment in Amazon EC2. To call GenerateRandom for a Nitro enclave, use the Amazon Web Services Nitro Enclaves SDK or any Amazon Web Services SDK. Use the Recipient parameter to provide the attestation document for the enclave. Instead of plaintext bytes, the response includes the plaintext bytes encrypted under the public key from the attestation document (CiphertextForRecipient).For information about the interaction between KMS and Amazon Web Services Nitro Enclaves, see How Amazon Web Services Nitro Enclaves uses KMS in the Key Management Service Developer Guide.

For more information about entropy and random number generation, see Key Management Service Cryptographic Details.

Cross-account use: Not applicable. GenerateRandom does not use any account-specific resources, such as KMS keys.

Required permissions: kms:GenerateRandom (IAM policy)

Eventual consistency: The KMS API follows an eventual consistency model. For more information, see KMS eventual consistency.

Method Signature

IMPORTING

Optional arguments:

iv_numberofbytes TYPE /AWS1/KMSNUMBEROFBYTESTYPE /AWS1/KMSNUMBEROFBYTESTYPE

The length of the random byte string. This parameter is required.

iv_customkeystoreid TYPE /AWS1/KMSCUSTOMKEYSTOREIDTYPE /AWS1/KMSCUSTOMKEYSTOREIDTYPE

Generates the random byte string in the CloudHSM cluster that is associated with the specified CloudHSM key store. To find the ID of a custom key store, use the DescribeCustomKeyStores operation.

External key store IDs are not valid for this parameter. If you specify the ID of an external key store, GenerateRandom throws an UnsupportedOperationException.

io_recipient TYPE REF TO /AWS1/CL_KMSRECIPIENTINFO /AWS1/CL_KMSRECIPIENTINFO

A signed attestation document from an Amazon Web Services Nitro enclave and the encryption algorithm to use with the enclave's public key. The only valid encryption algorithm is RSAES_OAEP_SHA_256.

This parameter only supports attestation documents for Amazon Web Services Nitro Enclaves. To include this parameter, use the Amazon Web Services Nitro Enclaves SDK or any Amazon Web Services SDK.

When you use this parameter, instead of returning plaintext bytes, KMS encrypts the plaintext bytes under the public key in the attestation document, and returns the resulting ciphertext in the CiphertextForRecipient field in the response. This ciphertext can be decrypted only with the private key in the enclave. The Plaintext field in the response is null or empty.

For information about the interaction between KMS and Amazon Web Services Nitro Enclaves, see How Amazon Web Services Nitro Enclaves uses KMS in the Key Management Service Developer Guide.

RETURNING

oo_output TYPE REF TO /aws1/cl_kmsgeneraterandomrsp /AWS1/CL_KMSGENERATERANDOMRSP

Domain /AWS1/RT_ACCOUNT_ID
Primitive Type NUMC

Examples

Syntax Example

This is an example of the syntax for calling the method. It includes every possible argument and initializes every possible value. The data provided is not necessarily semantically accurate (for example the value "string" may be provided for something that is intended to be an instance ID, or in some cases two arguments may be mutually exclusive). The syntax shows the ABAP syntax for creating the various data structures.

DATA(lo_result) = lo_client->/aws1/if_kms~generaterandom(
  io_recipient = new /aws1/cl_kmsrecipientinfo(
    iv_attestationdocument = '5347567362473873563239796247513D'
    iv_keyencryptionalgorithm = |string|
  )
  iv_customkeystoreid = |string|
  iv_numberofbytes = 123
).

This is an example of reading all possible response values

lo_result = lo_result.
IF lo_result IS NOT INITIAL.
  lv_plaintexttype = lo_result->get_plaintext( ).
  lv_ciphertexttype = lo_result->get_ciphertextforrecipient( ).
ENDIF.

To generate random data

The following example generates 32 bytes of random data.

DATA(lo_result) = lo_client->/aws1/if_kms~generaterandom( iv_numberofbytes = 32 ) .