generateRandom method

Future<GenerateRandomResponse> generateRandom({
  1. String? customKeyStoreId,
  2. int? numberOfBytes,
})

Returns a random byte string that is cryptographically secure.

By default, the random byte string is generated in AWS KMS. To generate the byte string in the AWS CloudHSM cluster that is associated with a custom key store, specify the custom key store ID.

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

Required permissions: kms:GenerateRandom (IAM policy)

May throw DependencyTimeoutException. May throw KMSInternalException. May throw CustomKeyStoreNotFoundException. May throw CustomKeyStoreInvalidStateException.

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

Parameter numberOfBytes : The length of the byte string.

Implementation

Future<GenerateRandomResponse> generateRandom({
  String? customKeyStoreId,
  int? numberOfBytes,
}) async {
  _s.validateStringLength(
    'customKeyStoreId',
    customKeyStoreId,
    1,
    64,
  );
  _s.validateNumRange(
    'numberOfBytes',
    numberOfBytes,
    1,
    1024,
  );
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'TrentService.GenerateRandom'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      if (customKeyStoreId != null) 'CustomKeyStoreId': customKeyStoreId,
      if (numberOfBytes != null) 'NumberOfBytes': numberOfBytes,
    },
  );

  return GenerateRandomResponse.fromJson(jsonResponse.body);
}