You need to sign in to do that
Don't have an account?
ramasubramanian.ar
Amazon S3 signature creation issue - version 4
http://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-header-based-auth.html
I am tying to do a HEAD request. Based on the above document I created the signature but getting 403 forbidden message.
Do you find any mistake in the above code?
I am tying to do a HEAD request. Based on the above document I created the signature but getting 403 forbidden message.
DateTime now = System.now(); String formattednow = now.formatGmt('yyyyMMdd')+'T'+now.formatGmt('hhmmss')+'Z'; //Canonical string String a = 'HEAD'+ '\n' + EncodingUtil.urlEncode('/bucketName/fileName.mp4', 'UTF-8') + '\n' + '\n' + 'host:s3.amazonaws.com'+'\n'+'x-amz-date:'+formattednow +'\n' + 'host;x-amz-date'+'\n'+EncodingUtil.convertToHex(Crypto.generateDigest('SHA-256', Blob.valueOf(''))); Blob b = Blob.valueOf(a); String canonical = EncodingUtil.convertToHex(Crypto.generateDigest('SHA-256', b)); System.debug('canonical:::--'+canonical); //'2015-10-09T06:33:08.090Z' String StringToSign = 'AWS4-HMAC-SHA256' + '\n' + formattednow + '\n' + '20151009/us-east-1/s3/aws4_request' + '\n' + canonical; Blob b1 = crypto.generateMac('HmacSHA256',Blob.valueOf('AWS4'+'AWSSECRETKEY'), Blob.valueOf('20151009')); Blob b2 = crypto.generateMac('HmacSHA256',b1, Blob.valueOf('us-east-1')); Blob b3 = crypto.generateMac('HmacSHA256',b2, Blob.valueOf('s3')); Blob signInKey = crypto.generateMac('HmacSHA256',b3, Blob.valueOf('aws4_request')); System.debug('AAA:::'+EncodingUtil.convertToHex(Crypto.generateMac('HmacSHA256', Blob.valueOf(StringToSign), signInKey)));
Do you find any mistake in the above code?
Good luck!