Skip to content

Instantly share code, notes, and snippets.

@jduncanator
Created December 22, 2013 08:18
Show Gist options
  • Save jduncanator/8079713 to your computer and use it in GitHub Desktop.
Save jduncanator/8079713 to your computer and use it in GitHub Desktop.
Simple node.js script to generate test vectors for crypto-browserify. For HMAC, the current test vectors take `boo` as the key (as seen below), for Hashes, just change `createHmac` to `createHash` and loose the 2nd parameter and run it again!
var crypto = require('crypto')
, fs = require('fs');
var algos = [ 'md4', 'md5', 'sha1', 'sha224', 'sha256' ];
var vectors = {};
algos.forEach(function(algo) {
vectors[algo] = {
'Test123': {
'hex': crypto.createHmac(algo, 'boo').update('Test123').digest('hex'),
'binary': crypto.createHmac(algo, 'boo').update('Test123').digest('binary'),
'base64': crypto.createHmac(algo, 'boo').update('Test123').digest('base64')
},
'hellø' : {
'hex': crypto.createHmac(algo, 'boo').update('hellø', 'utf8').digest('hex')
}
}
})
fs.writeFileSync('output.json', JSON.stringify(vectors, null, ' '))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment