mirror of https://github.com/BTCPrivate/copay.git
added Passphrase model and service
This commit is contained in:
parent
62b95ac122
commit
06b25db364
|
@ -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;
|
|
@ -0,0 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
var passphrase;
|
||||
angular.module('copay.passphrase').factory('Passphrase', function($rootScope) {
|
||||
passphrase = passphrase || new copay.Passphrase(config);
|
||||
return passphrase;
|
||||
});
|
Loading…
Reference in New Issue