尝试从KMS获取密钥时出现GRPC错误

时间:2019-03-27 18:28:30

标签: encryption key google-cloud-kms

我用KMS中的加密密钥创建了一个GCP项目。现在,我正在尝试使用KMS的密钥对数据进行加密。

public static void Encrypt(string projectId, string locationId, string keyRingId, string cryptoKeyId,string plaintextFile, string ciphertextFile)
    {
        KeyManagementServiceClient client = KeyManagementServiceClient.Create();
        CryptoKeyName cryptoKeyName =
            new CryptoKeyName(projectId, locationId, keyRingId, cryptoKeyId);

        byte[] plaintext = File.ReadAllBytes(plaintextFile);
        CryptoKeyPathName pathName = CryptoKeyPathName.Parse(cryptoKeyName.ToString());
        EncryptResponse result = client.Encrypt(pathName, ByteString.CopyFrom(plaintext));

        // Output encrypted data to a file.
        File.WriteAllBytes(ciphertextFile, result.Ciphertext.ToByteArray());
        Console.Write($"Encrypted file created: {ciphertextFile}");
    }
来自Google Cloud

示例代码。当我尝试运行此程序时,我得到:

`"Status(StatusCode=Unavailable, Detail=\"Connect Failed\")"` from grpc.core (`Exception thrown: 'Grpc.Core.RpcException' in mscorlib.dll`).

有人遇到类似的问题吗?或任何想法可能是什么原因?

0 个答案:

没有答案