I'm trying to encode an Amazon s3 bucket policy in base64 in node.js for the signature (more specifically the StringToSign), but can't seem to get the code right.
I'm using a default policy provided by amazon to test with because they provide the correct base64 encoding. ( The example given by amazon )
Their output is eyAiZXhwaXJhdGlvbiI6ICIyMDE1........
(Keeping it short because it's quite long)
I keep getting eyJleHBpcmF0aW9uIjoiMjAxNS0xMi0zMFQx.....
my code to generate this is:
var policyString = JSON.stringify(policy)
var policyBytes = utf8.encode(policyString)
var stringToSign = base64.encode(policyBytes)
where policy
is a variable holding the amazon policy in JSON format, and utf8
and base64
are node modules.
This might sound like a novice question but I've been staring at it for awhile now and any hlep would be appreciated!
I decoded the current partial values you have provided
eyAiZXhwaXJhdGlvbiI6ICIyMDE1
eyJleHBpcmF0aW9uIjoiMjAxNS0xMi0zMFQx
Respective outputs were:
{ "expiration": "2015
{"expiration":"2015-12-30T1
As you can see, in your policyString
you have removed some spaces. This is the reason for you to get a different output
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.