AWS v4 Signature with Crypto Browserify

node v4.9.1
version: 1.0.1
Use Crypto Browserify to calculate an AWS v4 signature as described at
const Crypto = require('crypto-browserify'); const { createHmac } = Crypto; const hmacSha256 = (signingKey, stringToSign) => { const hmac = createHmac('sha256', signingKey); hmac.write(stringToSign) hmac.end(); return; }; 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).toString('hex'); console.log(targetSignature == final, targetSignature, final);

no comments

    sign in to comment