Skip to content

Instantly share code, notes, and snippets.

@isaacs
Forked from Marak/gist:485068
Created July 21, 2010 20:27
Show Gist options
  • Save isaacs/485069 to your computer and use it in GitHub Desktop.
Save isaacs/485069 to your computer and use it in GitHub Desktop.
var sys = require('sys'),
crypto = require('crypto'),
algos = ["sha1", "md5", "sha256", "sha512", "ripemd160"],
encoding = "hex";
algos.forEach( function( algo) {
exports[ algo ] = function(data, salt) {
return (typeof salt === 'undefined')
? crypto.createHash(algo).update(data).digest(encoding)
: crypto.createHmac(algo, salt).update(data).digest(encoding)
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment