Created
July 21, 2010 20:26
-
-
Save Marak/485068 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sys = require('sys'), | |
crypto = require('crypto'), | |
algos = ["sha1", "md5", "sha256", "sha512", "ripemd160"], | |
encoding = "hex"; | |
algos.forEach( function( algo) { | |
exports[ algo ] = function(data, salt) { | |
var hash; | |
hash = crypto.createHash(algo).update(data).digest(encoding); | |
if( typeof salt != 'undefined'){ | |
hash = crypto.createHmac(algo, salt).update(data).digest(encoding); | |
} | |
return hash; | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment