2014-04-30 12:30:25 -07:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
function Passphrase(config) {
|
|
|
|
config = config || {};
|
2014-05-07 06:31:57 -07:00
|
|
|
this.salt = config.salt || 'mjuBtGybi/4=';
|
2014-04-30 12:30:25 -07:00
|
|
|
this.iterations = config.iterations || 1000;
|
|
|
|
};
|
|
|
|
|
|
|
|
Passphrase.prototype.get = function(password) {
|
|
|
|
var hash = CryptoJS.SHA256(CryptoJS.SHA256(password));
|
2014-04-30 12:36:20 -07:00
|
|
|
var salt = CryptoJS.enc.Base64.parse(this.salt);
|
2014-04-30 12:30:25 -07:00
|
|
|
var key512 = CryptoJS.PBKDF2(hash, salt, { keySize: 512/32, iterations: this.iterations });
|
|
|
|
|
|
|
|
return key512;
|
|
|
|
};
|
|
|
|
|
|
|
|
Passphrase.prototype.getBase64 = function(password) {
|
|
|
|
var key512 = this.get(password);
|
|
|
|
var keyBase64 = key512.toString(CryptoJS.enc.Base64);
|
|
|
|
|
|
|
|
return keyBase64;
|
|
|
|
};
|
|
|
|
|
2014-05-07 14:48:56 -07:00
|
|
|
Passphrase.prototype.getBase64Async = function(password,cb) {
|
|
|
|
var self = this;
|
|
|
|
setTimeout(function() {
|
|
|
|
var ret = self.getBase64(password);
|
|
|
|
return cb(ret);
|
|
|
|
},10);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-04-30 12:30:25 -07:00
|
|
|
module.exports = Passphrase;
|