0

这显示错误“我们计算的请求签名与您提供的签名不匹配。检查您的 AWS。

     string url;
    integer statuscode;
    String date1=json.serialize(Datetime.now());
    if(date1.contains('"')){
    date1=date1.replace('"','');}
    String algorithmName = 'HmacSHA256';
    date1=date1.substring(0,(date1.length()-5));
     date1=date1+'Z';
     date1=EncodingUtil.UrlEncode(date1,'UTF-8');    
     String Action=EncodingUtil.UrlEncode('CreateTopic','UTF-8');
     String AccessKey=EncodingUtil.UrlEncode('APIKEY','UTF-8'); // API key hide due to security resion but i check it work fine for SES
     String Signaturemethod=EncodingUtil.UrlEncode('HmacSHA256','UTF-8');
     string str= 'GET\nsns.us-east-1.amazonaws.com\n/\nAction='+Action+'&Name=Testtopics&AWSAccessKeyId='+AccessKey+'&Timestamp='+date1+'&SignatureVersion=2&SignatureMethod='+Signaturemethod; 
    Blob mac = Crypto.generateMac(algorithmName,Blob.valueOf(str),Blob.valueOf('SECURITYKEY')); //blob value of key used in signature
    url='https://sns.us-east-1.amazonaws.com/?Action=CreateTopic&Name=Testtopics&AWSAccessKeyId=ACCESSKEY&Timestamp='+date1+'&SignatureVersion=2&SignatureMethod=HmacSHA256&Signature='+EncodingUtil.UrlEncode(EncodingUtil.base64Encode(mac),'UTF-8'); // final url   
4

2 回答 2

0

我对 AWS 没有太多想法,但以下是我能找到的。无法在任何地方测试这些东西来找出问题所在。

以下错误消息的常见原因是未正确创建要签名的字符串,例如忘记对 Amazon S3 存储桶名称中的冒号 (:) 和正斜杠 (/) 等字符进行 URL 编码。

<Error>
    <Type>Sender</Type>
    <Code>SignatureDoesNotMatch</Code>
    <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.</Message>
</Error>

http://docs.aws.amazon.com/general/latest/gr/signature-version-2.html

http://docs.aws.amazon.com/AmazonS3/latest/dev/BucketRestrictions.html

于 2013-10-10T11:55:49.370 回答
0

看起来您可能在 url 末尾缺少一个尾随单引号。看看这是否有所作为。

url="https://sns.us-east-1.amazonaws.com/?Action=CreateTopic&Name=Testtopics&AWSAccessKeyId=ACCESSKEY&Timestamp='+date1+'&SignatureVersion=2&SignatureMethod=HmacSHA256&Signature='+EncodingUtil.UrlEncode(EncodingUtil.base64Encode(mac),'UTF-8')+"'";
于 2013-10-10T14:43:42.583 回答