Skip to content

Instantly share code, notes, and snippets.

@calvinchengx
Created May 28, 2014 07:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save calvinchengx/24cf8c48fcd2f0182704 to your computer and use it in GitHub Desktop.
Save calvinchengx/24cf8c48fcd2f0182704 to your computer and use it in GitHub Desktop.
Example module export for nodejs libraries
var sjcl = require('sjcl');
var RNCryptor = {};
/*
Takes password string and salt WordArray
Returns key bitArray
*/
module.exports.KeyForPassword = RNCryptor.KeyForPassword = function(password, salt) {
var hmacSHA1 = function (key) {
var hasher = new sjcl.misc.hmac(key, sjcl.hash.sha1);
this.encrypt = function () {
return hasher.encrypt.apply(hasher, arguments);
};
};
return sjcl.misc.pbkdf2(password, salt, 10000, 32 * 8, hmacSHA1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment