in helpers/wrapped-key/wrapped_key.py [0:0]
def generate_random_bytes(project_id, location_id, num_bytes, client):
"""
Generate random bytes with entropy sourced from the given location.
Args:
project_id (string): Google Cloud project ID (e.g. 'my-project').
location_id (string): Cloud KMS location (e.g. 'us-east1').
num_bytes (integer): number of bytes of random data.
client (KeyManagementServiceClient):
Google Cloud Key Management Service.
Returns:
bytes: Encrypted ciphertext.
"""
# Build the location name.
location_name = client.common_location_path(project_id, location_id)
# Call the API.
protection_level = kms.ProtectionLevel.HSM
random_bytes_response = client.generate_random_bytes(
request={'location': location_name, 'length_bytes': num_bytes,
'protection_level': protection_level})
return random_bytes_response.data