Membuat byte acak

Topik ini menunjukkan cara mengambil byte acak dari generator angka acak di Cloud HSM.

Sebelum memulai

  • Berikan izin cloudkms.locations.generateRandomBytes di lokasi cloud tempat layanan Anda akan membuat byte acak. Anda dapat mempelajari izin di Cloud Key Management Service di Izin dan peran.

Membuat byte acak

C#

Untuk menjalankan kode ini, siapkan lingkungan pengembangan C# terlebih dahulu dan instal SDK C# Cloud KMS.


using Google.Api.Gax.ResourceNames;
using Google.Cloud.Kms.V1;

public class GenerateRandomBytesSample
{
    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