added Passphrase model and service

This commit is contained in:
Mario Colque 2014-04-30 16:30:25 -03:00
parent 62b95ac122
commit 06b25db364
2 changed files with 31 additions and 0 deletions

View File

@ -0,0 +1,24 @@
'use strict';
function Passphrase(config) {
config = config || {};
this.salt = config.storageSalt;
this.iterations = config.iterations || 1000;
};
Passphrase.prototype.get = function(password) {
var hash = CryptoJS.SHA256(CryptoJS.SHA256(password));
var salt = CryptoJS.enc.Hex.parse(this.salt);
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;
};
module.exports = Passphrase;

View File

@ -0,0 +1,7 @@
'use strict';
var passphrase;
angular.module('copay.passphrase').factory('Passphrase', function($rootScope) {
passphrase = passphrase || new copay.Passphrase(config);
return passphrase;
});