我用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`).
有人遇到类似的问题吗?或任何想法可能是什么原因?