向 Amazon KMS 发送加密请求时访问被拒绝
AccessDenied when sending Encrypt request to Amazon KMS
我想使用 Amazon KMS 服务加密字符串。我的凭据有效,我可以使用客户端获取密钥列表,但是当我尝试加密我的字符串时,我得到了 400。这是我的代码(我打赌我遗漏了一些简单的东西):
public static string Encrypt(string str, string awsRegion, string theKey)
{
var keyId = "arn:aws:kms:" + awsRegion + ":0987654321:key/" + thekey;
using (var client = new AmazonKeyManagementServiceClient(AWSId, AWSSK, RegionEndpoint.USEast1))
{
var req = new EncryptRequest
{
KeyId = keyId,
Plaintext = new MemoryStream(Encoding.UTF8.GetBytes(str))
};
var blob = client.Encrypt(req).CiphertextBlob;
return new StreamReader(blob).ReadToEnd();
}
}
这可能是什么原因造成的?
我也在 visual studio 中设置了我的个人资料。
编辑 1:错误信息是:
Error making request with Error Code AccessDeniedException and Http
Status Code BadRequest. No further error information was returned by
the service.
事实证明,keyId 字符串中区域和键之间的整数不是任意的。
我通过获取我可用的键列表、找到相应的键并将该整数复制到我的 keyId 字符串中来代替 0987654321 来使其工作。
我想使用 Amazon KMS 服务加密字符串。我的凭据有效,我可以使用客户端获取密钥列表,但是当我尝试加密我的字符串时,我得到了 400。这是我的代码(我打赌我遗漏了一些简单的东西):
public static string Encrypt(string str, string awsRegion, string theKey)
{
var keyId = "arn:aws:kms:" + awsRegion + ":0987654321:key/" + thekey;
using (var client = new AmazonKeyManagementServiceClient(AWSId, AWSSK, RegionEndpoint.USEast1))
{
var req = new EncryptRequest
{
KeyId = keyId,
Plaintext = new MemoryStream(Encoding.UTF8.GetBytes(str))
};
var blob = client.Encrypt(req).CiphertextBlob;
return new StreamReader(blob).ReadToEnd();
}
}
这可能是什么原因造成的?
我也在 visual studio 中设置了我的个人资料。
编辑 1:错误信息是:
Error making request with Error Code AccessDeniedException and Http Status Code BadRequest. No further error information was returned by the service.
事实证明,keyId 字符串中区域和键之间的整数不是任意的。
我通过获取我可用的键列表、找到相应的键并将该整数复制到我的 keyId 字符串中来代替 0987654321 来使其工作。