Would you like to clone this notebook?

When you clone a notebook you are able to make changes without affecting the original notebook.


AWS v4 Signature with CryptoJS

node v4.9.1
version: 1.0.0
Use CryptoJS to calculate an AWS v4 signature as described at http://docs.aws.amazon.com/general/latest/gr/signature-v4-test-suite.html#signature-v4-test-suite-task-3.
const Crypto = require('crypto-js'); const hmacSha256 = (stringToSign, signingKey) => { return Crypto.HmacSHA256(signingKey, stringToSign, { asBytes: true }); }; const stringToSign = `AWS4-HMAC-SHA256 20150830T123600Z 20150830/us-east-1/service/aws4_request 816cd5b414d056048ba4f7c5386d6e0533120fb1fcfa93762cf0fc39e2cf19e0`; const targetSignature = 'b97d918cfa904a5beff61c982a1b6f458b799221646efd99d3219ec94cdf2500'; const secretKey = 'wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY'; const requestScope = stringToSign.split('\n')[2]; const [date, region, service, signatureType] = requestScope.split('/'); const round1 = hmacSha256(`AWS4${secretKey}`, date); const round2 = hmacSha256(round1, region); const round3 = hmacSha256(round2, service); const round4 = hmacSha256(round3, signatureType); const final = hmacSha256(round4, stringToSign); console.log(targetSignature == final.toString(), targetSignature, final.toString());

no comments

    sign in to comment