"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 detail"
Below is my SignatureHelper (based on Amazon class libraries).
public string SignRequest(Dictionary<string, string> parametersUrl, Dictionary<string, string> parametersSignture)
{
var secret = Encoding.UTF8.GetBytes(parametersSignture["Secret"]);
var signer = new HMACSHA256(secret);
var stringToSign = CalculateStringToSign(parametersUrl, parametersSignture);
var toSign = Encoding.UTF8.GetBytes(stringToSign);
var sigBytes = signer.ComputeHash(toSign);
var signature = Convert.ToBase64String(sigBytes);
return signature;
}
private static string CalculateStringToSign(IDictionary<string, string> parameters, IDictionary<string, string> parametersSignture)
{
var sorted = new SortedDictionary<string, string>(parameters, StringComparer.Ordinal);
var data = new StringBuilder();
data.Append(parametersSignture["RequestMethod"]);
data.Append("\n");
var endpoint = new Uri(parametersSignture["EndPoint"]);
data.Append(endpoint.Host);
if (endpoint.Port != 443 && endpoint.Port != 80)
{
data.Append(":")
.Append(endpoint.Port);
}
data.Append("\n");
var uri = endpoint.AbsolutePath;
if (uri.Length == 0)
{
uri = "/";
}
data.Append(UrlEncode(uri, true));
data.Append("\n");
foreach (var pair in sorted.Where(pair => pair.Value != null))
{
data.Append(UrlEncode(pair.Key, false));
data.Append("=");
data.Append(UrlEncode(pair.Value, false));
data.Append("&");
}
var result = data.ToString();
return result.Remove(result.Length - 1);
}
private static string UrlEncode(string data, bool path)
{
var encoded = new StringBuilder();
var unreservedChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.~" + (path ? "/" : string.Empty);
foreach (char symbol in Encoding.UTF8.GetBytes(data))
{
if (unreservedChars.IndexOf(symbol) != -1)
{
encoded.Append(symbol);
}
else
{
encoded.Append("%" + string.Format("{0:X2}", (int)symbol));
}
}
return encoded.ToString();
}
This is my data:
CalculateStringToSign POST
mws.amazonservices.com
/
AWSAccessKeyId=***&Action=SubmitFeed&FeedType=_POST_PRODUCT_DATA_&MWSAuthToken=****&Merchant=***&PurgeAndReplace=false&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2015-06-30T13%3A47%3A42Z&Version=2009-01-01
URL
"http://ift.tt/1LFLIxM"
This is what I receive back
Code: SignatureDoesNotMatch
Message: 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.
I think its something within my helper (unsure what as I've look at many code samples and it seems the same.
Thanks,
Clare
Aucun commentaire:
Enregistrer un commentaire