node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »



High-level crypto library for Node.js

Krypto aims to promote best practices in cryptography by making doing the Right Thing(tm) easier, and more obvious.

So far, Krypto exposes a few digest functions that are more convenient than using crypto.Hash directly. There's also a function for hashing passwords, and one for generating salts.


var assert = require('assert')
var krypto = require('krypto');
var message = 'ZANrmkIGgVFXVBxsrbRbivcY5JSidnPB34Kr5lokBT6xWvFvW0';
var md5 = '4396515f67fcd24c3db6cfa93113d169';
var sha1 = 'd629109a238bb58092340016d7d9f93899ec390a';
var sha512 = 'a3de23a73df0d9bfa1c70ae0208dfabc309874f1d44c75736770356bd0a5d1180b0c18327fcc43e5d2dd850c3027c5f15eacb651315531fe323dcc27c8e1c613';
assert.equal(krypto.md5(message), md5);
assert.equal(krypto.sha1(message), sha1);
assert.equal(krypto.sha512(message), sha512);
var password = "fuzzybunnies";
var salt = new Buffer('4396515f67fcd24c3db6cfa93113d169', 'hex');
assert.equal(salt.length, 16);
assert.equal(krypto.salt().length, 16);
krypto.hashPassword(password, salt, function(err, digest) {
  assert.equal(digest, '05a97bd77f4f9c5e839853742702491f9849ddca9f46b1c7ba250a5bb1631ff7');