【发布时间】:2017-10-01 15:15:31
【问题描述】:
所以我试图通过 UPC 称为搜索项的方法向亚马逊的 API 发出请求。到目前为止,我在这里所做的如下:
var client = new RestClient("http://webservices.amazon.com/onca/xml");
string itemid = "694318020913";
var timestamp = DateTime.UtcNow.ToString("o");
var signature = getSignatureKey("some key here", timestamp, "east-us-1", "iam");
var request = new RestRequest(Method.POST);
request.AddParameter("application/x-www-form-urlencoded", "Service=AWSECommerceService&Operation=ItemLookup&ResponseGroup=Large&SearchIndex=All&IdType=UPC&ItemId="+itemid+"&AWSAccessKeyId=accesssKey&AssociateTag=associateTag&Timestamp=" + timestamp + "&Signature=" + signature, ParameterType.RequestBody);
var res = client.Execute(request).Content;
这些是我在亚马逊文档中找到的用于计算签名的辅助方法:
static byte[] HmacSHA256(String data, byte[] key)
{
string algorithm = "HmacSHA256";
KeyedHashAlgorithm kha = KeyedHashAlgorithm.Create(algorithm);
kha.Key = key;
return kha.ComputeHash(Encoding.UTF8.GetBytes(data));
}
static byte[] getSignatureKey(string key, string dateStamp, string regionName, string serviceName)
{
byte[] kSecret = Encoding.UTF8.GetBytes(("AWS4" + key).ToCharArray());
byte[] kDate = HmacSHA256(dateStamp, kSecret);
byte[] kRegion = HmacSHA256(regionName, kDate);
byte[] kService = HmacSHA256(serviceName, kRegion);
byte[] kSigning = HmacSHA256("aws4_request", kService);
return kSigning;
}
现在让我感到困惑的是,我收到了来自亚马逊的以下消息:
The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details c# .net
我的问题是:
-
在这个 getSignatureKey 方法中,我实际上必须传递哪个密钥?
- 我有几把来自亚马逊的钥匙,它们是:
- 访问密钥、秘密密钥、关联密钥?
我在这里做错了什么?有人可以帮帮我吗?
【问题讨论】:
-
有人吗?我怀疑这可能是签名类型本身的问题,该方法返回 byte[] 然后我简单地将其转换为字符串...?不知何故,我觉得这不是正确的做法?
-
"我实际上必须通过哪个键?"密钥
-
@User987 你已经找到解决方案了吗?我遇到了同样的问题。
-
有人找到解决方案了吗?
标签: c# asp.net asp.net-mvc amazon-web-services amazon-s3