+ Start a Discussion
RajusRajus 

Amzon S3 authentication issue.

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.

RajusRajus

Hi,

 

Thank you so much for your reply. I went through that thread, and did some changes in my code .Still i am getting the same error.Could you please let me know if there is anything which i need to change.

 

Following is my code which i am using to get the list of all objects.

 

Datetime now = DateTime.now();
String dateString = Datetime.now().formatGmt('EEE, dd MMM yyyy HH:mm:ss Z');
String stringtosign = 'GET\n\n\n'+dateString;
String signingKey = EncodingUtil.base64Encode(Blob.valueOf('xxxxxxxxxxxxx'));
Blob mac = Crypto.generateMac('HMacSHA1', blob.valueof(stringtosign),blob.valueof(signingKey));
string macUrl = EncodingUtil.base64Encode(mac);


httpRequest con = new HttpRequest();
con.setHeader('Authorization', 'AWS xxxxxxxxxx:'+macUrl);
con.setEndPoint('https://s3.amazonaws.com');
con.setHeader('Host','VHS_Trial_Demo.s3.amazonaws.com');
con.setHeader('Date',dateString);
con.setMethod('GET');
Http http = new Http();
HTTPResponse res = http.send(con);
system.debug('========'+res.getBody());

 

Thanks,

Rajesh.

dwatson1.3922234062052024E12dwatson1.3922234062052024E12
@Rajesh, did you find a solution for this? I am facing the same issue.

Thanks,
David