Skip to content

Instantly share code, notes, and snippets.

@indexzero
Created January 28, 2011 20:56
Show Gist options
  • Save indexzero/800931 to your computer and use it in GitHub Desktop.
Save indexzero/800931 to your computer and use it in GitHub Desktop.
Additions to node_hash to pass optional encoding. **This should be in node core imo**
var sys = require('sys'),
hash = require('./lib/hash');
// a user's password, hash this please
var user_password = "password";
// don't expose your salt
var salt = "sUp3rS3CRiT$@lt";
/****** md5 ******/
var md5 = hash.md5(user_password, 'utf8');
sys.puts(md5);
var salted_md5 = hash.md5(user_password, salt, 'utf8');
sys.puts(salted_md5);
/****** sha1 ******/
var sha1 = hash.sha1(user_password, 'utf8');
sys.puts(sha1);
var salted_sha1 = hash.sha1(user_password, salt, 'utf8');
sys.puts(salted_sha1);
/****** sha256 ******/
var sha256 = hash.sha256(user_password);
sys.puts(sha256);
var salted_sha256 = hash.sha256(user_password, salt, 'utf8');
sys.puts(salted_sha256);
/****** sha512 ******/
var sha512 = hash.sha512(user_password, 'utf8');
sys.puts(sha512);
var salted_sha512 = hash.sha512(user_password, salt, 'utf8');
sys.puts(salted_sha512);
/****** ripemd160 ******/
var ripemd160 = hash.ripemd160(user_password, 'utf8');
sys.puts(ripemd160);
var salted_ripemd160 = hash.ripemd160(user_password, salt, 'utf8');
sys.puts(salted_ripemd160);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment