mirror of https://github.com/BTCPrivate/copay.git
get LocalEncrypted working the same way as File
This commit is contained in:
parent
f599331351
commit
0020faa84a
|
@ -25,12 +25,26 @@ Storage.prototype._setPassphrase = function(password) {
|
|||
pps[this.__uniqueid] = password;
|
||||
}
|
||||
|
||||
Storage.prototype._encrypt = function(data) {
|
||||
return CryptoJS.AES.encrypt(data, this._getPassphrase());
|
||||
Storage.prototype._encrypt = function(string) {
|
||||
var encrypted = CryptoJS.AES.encrypt(string, this._getPassphrase());
|
||||
var encryptedBase64 = encrypted.toString();
|
||||
return encryptedBase64;
|
||||
};
|
||||
|
||||
Storage.prototype._decrypt = function(encrypted) {
|
||||
return CryptoJS.AES.decrypt(encrypted, this._getPassphrase());
|
||||
Storage.prototype._encryptObj = function(obj) {
|
||||
var string = JSON.stringify(obj);
|
||||
return this._encrypt(string);
|
||||
};
|
||||
|
||||
Storage.prototype._decrypt = function(base64) {
|
||||
var decrypted = CryptoJS.AES.decrypt(base64, this._getPassphrase());
|
||||
var decryptedStr = decrypted.toString(CryptoJS.enc.Utf8);
|
||||
return decryptedStr;
|
||||
};
|
||||
|
||||
Storage.prototype._decryptObj = function(base64) {
|
||||
var decryptedStr = this._decrypt(base64);
|
||||
return JSON.parse(decryptedStr);
|
||||
};
|
||||
|
||||
Storage.prototype._read = function(k) {
|
||||
|
@ -53,6 +67,17 @@ Storage.prototype._write = function(k,v) {
|
|||
localStorage.setItem(k, v);
|
||||
};
|
||||
|
||||
Storage.prototype.setFromObj = function(walletId, obj) {
|
||||
for (var i in keys) {
|
||||
var key = keys[0];
|
||||
obj[key] = this.get(walletId, key);
|
||||
}
|
||||
};
|
||||
|
||||
Storage.prototype.setFromEncryptedObj = function(walletId, base64) {
|
||||
|
||||
};
|
||||
|
||||
Storage.prototype.getEncryptedObj = function(walletId) {
|
||||
var keys = this._getWalletKeys();
|
||||
var obj = {};
|
||||
|
|
|
@ -53,8 +53,8 @@ if (typeof process === 'undefined' || !process.version) {
|
|||
storage.set('walletId', 'test', 'testval');
|
||||
var obj = {test:'testval'};
|
||||
var encrypted = storage.getEncryptedObj('walletId');
|
||||
encrypted.length.should.equal(96);
|
||||
encrypted.slice(0,6).should.equal("53616c");
|
||||
encrypted.length.should.be.greaterThan(10);
|
||||
//encrypted.slice(0,6).should.equal("53616c");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue