AWS SDK <-> Crypto Browserify

node v4.9.1
version: 1.0.0
endpointsharetweet
Map cryptographic functions of Crypto Browserify and the AWS SDK. Useful for converting code from one library to the other.
const AWS = require('aws-sdk'); const crypto = require('crypto-browserify'); const secretKey = 'abc123'; const AWSUtils = { hmac: (input) => AWS.util.crypto.lib.createHmac('sha256', secretKey) .update(input) .digest(), hmacHex: (input) => AWS.util.crypto.lib.createHmac('sha256', secretKey) .update(input) .digest('hex'), md5: (input) => AWS.util.crypto.md5(input, 'base64'), sha: (input) => AWS.util.crypto.sha256(input, 'hex'), }; const CryptoUtils = { hmac: (input) => crypto.createHmac('sha256', secretKey).update(input).digest(), hmacHex: (input) => crypto.createHmac('sha256', secretKey).update(input).digest('hex'), md5: (input) => crypto.createHash('md5').update(input).digest('base64'), sha: (input) => crypto.createHash('sha256').update(input).digest('hex'), }; const randomInput = ((new Date).getTime()).toString(); console.log('hmac', AWSUtils.hmac(randomInput).equals(CryptoUtils.hmac(randomInput))); console.log('hmacHex', AWSUtils.hmacHex(randomInput) === CryptoUtils.hmacHex(randomInput)); console.log('md5', AWSUtils.md5(randomInput) === CryptoUtils.md5(randomInput)); console.log('sha', AWSUtils.sha(randomInput) === CryptoUtils.sha(randomInput));
Loading…

no comments

    sign in to comment