added Passphrase model and service
This commit is contained in:
parent
62b95ac122
commit
06b25db364
2 changed files with 31 additions and 0 deletions
24
js/models/core/Passphrase.js
Normal file
24
js/models/core/Passphrase.js
Normal 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;
|
||||
7
js/services/passphrase.js
Normal file
7
js/services/passphrase.js
Normal 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;
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue