public byte[] GenerateRandomBytes( string projectId = "my-project", string locationId = "us-east1", int numBytes = 256) { // Create the client. KeyManagementServiceClient client = KeyManagementServiceClient.Create(); // Build the location name. LocationName locationName = new LocationName(projectId, locationId); // Call the API. GenerateRandomBytesResponse result = client.GenerateRandomBytes(locationName.ToString(), numBytes, ProtectionLevel.Hsm); // The data comes back as raw bytes, which may include non-printable // characters. To print the result, you could encode it as base64. // string encodedData = result.Data.ToBase64(); return(result.Data.ToByteArray()); }