• dwatson1.3922234062052024E12
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

Hi All,

 

I am facing one issue since two weeks .The issue is i am not able to authenticate the amazon s3 Rest  request properly and getting the following error.

 

Error:The request signature we calculated does not match the signature you provided.Check your key and signing method.

 

Follwoing is my code:

String dateString = Datetime.now().formatGmt('EEE, dd MMM yyyy HH:mm:ss Z');
system.debug('=========='+dateString);
string stringToSign = 'GET\n\n\n'+dateString';
Blob mac = Crypto.generateMac('hmacSHA1', Blob.valueOf(stringToSign), Blob.valueOf('xxxxxxxx'));
stringToSign = EncodingUtil.base64Encode(mac);
//stringToSign = EncodingUtil.urlEncode(stringToSign, 'UTF-8');
httpRequest con = new HttpRequest();
system.debug('**********'+stringToSign);
con.setHeader('Authorization', 'AWS xxxxxx:'+stringToSign);
con.setEndPoint('https://s3.amazonaws.com');
con.setHeader('Host','xxxxx.s3.amazonaws.com');
system.debug('====date format'+dateString);
con.setHeader('Date',dateString);
//con.setHeader('Content-Type','application/xml');
con.setMethod('GET');
Http http = new Http();
HTTPResponse res = http.send(con);
system.debug('========'+res.getBody());

 

 

Can any one please help me out on this.

Thanx in advance.

  • October 11, 2013
  • Like
  • 0