secure-ls2 2.0.5 → 2.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/secure-ls2.js +978 -978
- package/dist/secure-ls2.js.map +1 -1
- package/dist/secure-ls2.min.js +2 -2
- package/dist/secure-ls2.min.js.map +1 -1
- package/package.json +8 -8
package/dist/secure-ls2.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* secure-ls2 - v2.0.
|
|
2
|
+
* secure-ls2 - v2.0.6
|
|
3
3
|
* URL - https://github.com/softvar/secure-ls
|
|
4
4
|
*
|
|
5
5
|
* The MIT License (MIT)
|
|
@@ -46,855 +46,271 @@
|
|
|
46
46
|
return /******/ (() => { // webpackBootstrap
|
|
47
47
|
/******/ var __webpack_modules__ = ({
|
|
48
48
|
|
|
49
|
-
/***/ "./
|
|
50
|
-
|
|
51
|
-
!*** ./
|
|
52
|
-
|
|
53
|
-
/***/ ((
|
|
49
|
+
/***/ "./node_modules/crypto-js/aes.js":
|
|
50
|
+
/*!***************************************!*\
|
|
51
|
+
!*** ./node_modules/crypto-js/aes.js ***!
|
|
52
|
+
\***************************************/
|
|
53
|
+
/***/ (function(module, exports, __webpack_require__) {
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
encode: function (e) {
|
|
63
|
-
let t = '';
|
|
64
|
-
let n, r, i, s, o, u, a;
|
|
65
|
-
let f = 0;
|
|
66
|
-
e = Base64._utf8Encode(e);
|
|
67
|
-
while (f < e.length) {
|
|
68
|
-
n = e.charCodeAt(f++);
|
|
69
|
-
r = e.charCodeAt(f++);
|
|
70
|
-
i = e.charCodeAt(f++);
|
|
71
|
-
s = n >> 2;
|
|
72
|
-
o = (n & 3) << 4 | r >> 4;
|
|
73
|
-
u = (r & 15) << 2 | i >> 6;
|
|
74
|
-
a = i & 63;
|
|
75
|
-
if (isNaN(r)) {
|
|
76
|
-
u = a = 64;
|
|
77
|
-
} else if (isNaN(i)) {
|
|
78
|
-
a = 64;
|
|
79
|
-
}
|
|
80
|
-
t = t + this._keyStr.charAt(s) + this._keyStr.charAt(o) + this._keyStr.charAt(u) + this._keyStr.charAt(a);
|
|
81
|
-
}
|
|
82
|
-
return t;
|
|
83
|
-
},
|
|
84
|
-
decode: function (e) {
|
|
85
|
-
let t = '';
|
|
86
|
-
let n, r, i;
|
|
87
|
-
let s, o, u, a;
|
|
88
|
-
let f = 0;
|
|
89
|
-
e = e.replace(/[^A-Za-z0-9+/=]/g, '');
|
|
90
|
-
while (f < e.length) {
|
|
91
|
-
s = this._keyStr.indexOf(e.charAt(f++));
|
|
92
|
-
o = this._keyStr.indexOf(e.charAt(f++));
|
|
93
|
-
u = this._keyStr.indexOf(e.charAt(f++));
|
|
94
|
-
a = this._keyStr.indexOf(e.charAt(f++));
|
|
95
|
-
n = s << 2 | o >> 4;
|
|
96
|
-
r = (o & 15) << 4 | u >> 2;
|
|
97
|
-
i = (u & 3) << 6 | a;
|
|
98
|
-
t = t + String.fromCharCode(n);
|
|
99
|
-
if (u !== 64) {
|
|
100
|
-
t = t + String.fromCharCode(r);
|
|
101
|
-
}
|
|
102
|
-
if (a !== 64) {
|
|
103
|
-
t = t + String.fromCharCode(i);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
t = Base64._utf8Decode(t);
|
|
107
|
-
return t;
|
|
108
|
-
},
|
|
109
|
-
_utf8Encode: function (e) {
|
|
110
|
-
e = e.replace(/\r\n/g, '\n');
|
|
111
|
-
let t = '';
|
|
112
|
-
for (let n = 0; n < e.length; n++) {
|
|
113
|
-
let r = e.charCodeAt(n);
|
|
114
|
-
if (r < 128) {
|
|
115
|
-
t += String.fromCharCode(r);
|
|
116
|
-
} else if (r > 127 && r < 2048) {
|
|
117
|
-
t += String.fromCharCode(r >> 6 | 192);
|
|
118
|
-
t += String.fromCharCode(r & 63 | 128);
|
|
119
|
-
} else {
|
|
120
|
-
t += String.fromCharCode(r >> 12 | 224);
|
|
121
|
-
t += String.fromCharCode(r >> 6 & 63 | 128);
|
|
122
|
-
t += String.fromCharCode(r & 63 | 128);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
return t;
|
|
126
|
-
},
|
|
127
|
-
_utf8Decode: function (e) {
|
|
128
|
-
let t = '';
|
|
129
|
-
let n = 0;
|
|
130
|
-
let r, c2, c3;
|
|
131
|
-
r = c2 = 0;
|
|
132
|
-
while (n < e.length) {
|
|
133
|
-
r = e.charCodeAt(n);
|
|
134
|
-
if (r < 128) {
|
|
135
|
-
t += String.fromCharCode(r);
|
|
136
|
-
n++;
|
|
137
|
-
} else if (r > 191 && r < 224) {
|
|
138
|
-
c2 = e.charCodeAt(n + 1);
|
|
139
|
-
t += String.fromCharCode((r & 31) << 6 | c2 & 63);
|
|
140
|
-
n += 2;
|
|
141
|
-
} else {
|
|
142
|
-
c2 = e.charCodeAt(n + 1);
|
|
143
|
-
c3 = e.charCodeAt(n + 2);
|
|
144
|
-
t += String.fromCharCode((r & 15) << 12 | (c2 & 63) << 6 | c3 & 63);
|
|
145
|
-
n += 3;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
return t;
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (Base64);
|
|
55
|
+
;(function (root, factory, undef) {
|
|
56
|
+
if (true) {
|
|
57
|
+
// CommonJS
|
|
58
|
+
module.exports = exports = factory(__webpack_require__(/*! ./core */ "./node_modules/crypto-js/core.js"), __webpack_require__(/*! ./enc-base64 */ "./node_modules/crypto-js/enc-base64.js"), __webpack_require__(/*! ./md5 */ "./node_modules/crypto-js/md5.js"), __webpack_require__(/*! ./evpkdf */ "./node_modules/crypto-js/evpkdf.js"), __webpack_require__(/*! ./cipher-core */ "./node_modules/crypto-js/cipher-core.js"));
|
|
59
|
+
}
|
|
60
|
+
else {}
|
|
61
|
+
}(this, function (CryptoJS) {
|
|
152
62
|
|
|
153
|
-
|
|
63
|
+
(function () {
|
|
64
|
+
// Shortcuts
|
|
65
|
+
var C = CryptoJS;
|
|
66
|
+
var C_lib = C.lib;
|
|
67
|
+
var BlockCipher = C_lib.BlockCipher;
|
|
68
|
+
var C_algo = C.algo;
|
|
154
69
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
70
|
+
// Lookup tables
|
|
71
|
+
var SBOX = [];
|
|
72
|
+
var INV_SBOX = [];
|
|
73
|
+
var SUB_MIX_0 = [];
|
|
74
|
+
var SUB_MIX_1 = [];
|
|
75
|
+
var SUB_MIX_2 = [];
|
|
76
|
+
var SUB_MIX_3 = [];
|
|
77
|
+
var INV_SUB_MIX_0 = [];
|
|
78
|
+
var INV_SUB_MIX_1 = [];
|
|
79
|
+
var INV_SUB_MIX_2 = [];
|
|
80
|
+
var INV_SUB_MIX_3 = [];
|
|
160
81
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
/* harmony import */ var crypto_js_rabbit__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(crypto_js_rabbit__WEBPACK_IMPORTED_MODULE_4__);
|
|
173
|
-
/* harmony import */ var crypto_js_rc4__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! crypto-js/rc4 */ "./node_modules/crypto-js/rc4.js");
|
|
174
|
-
/* harmony import */ var crypto_js_rc4__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(crypto_js_rc4__WEBPACK_IMPORTED_MODULE_5__);
|
|
175
|
-
/* harmony import */ var crypto_js_tripledes__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! crypto-js/tripledes */ "./node_modules/crypto-js/tripledes.js");
|
|
176
|
-
/* harmony import */ var crypto_js_tripledes__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(crypto_js_tripledes__WEBPACK_IMPORTED_MODULE_6__);
|
|
177
|
-
/* harmony import */ var lz_string_libs_lz_string__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! lz-string/libs/lz-string */ "./node_modules/lz-string/libs/lz-string.js");
|
|
178
|
-
/* harmony import */ var lz_string_libs_lz_string__WEBPACK_IMPORTED_MODULE_7___default = /*#__PURE__*/__webpack_require__.n(lz_string_libs_lz_string__WEBPACK_IMPORTED_MODULE_7__);
|
|
179
|
-
/* harmony import */ var _Base64__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./Base64 */ "./src/Base64.js");
|
|
82
|
+
// Compute lookup tables
|
|
83
|
+
(function () {
|
|
84
|
+
// Compute double table
|
|
85
|
+
var d = [];
|
|
86
|
+
for (var i = 0; i < 256; i++) {
|
|
87
|
+
if (i < 128) {
|
|
88
|
+
d[i] = i << 1;
|
|
89
|
+
} else {
|
|
90
|
+
d[i] = (i << 1) ^ 0x11b;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
180
93
|
|
|
94
|
+
// Walk GF(2^8)
|
|
95
|
+
var x = 0;
|
|
96
|
+
var xi = 0;
|
|
97
|
+
for (var i = 0; i < 256; i++) {
|
|
98
|
+
// Compute sbox
|
|
99
|
+
var sx = xi ^ (xi << 1) ^ (xi << 2) ^ (xi << 3) ^ (xi << 4);
|
|
100
|
+
sx = (sx >>> 8) ^ (sx & 0xff) ^ 0x63;
|
|
101
|
+
SBOX[x] = sx;
|
|
102
|
+
INV_SBOX[sx] = x;
|
|
181
103
|
|
|
104
|
+
// Compute multiplication
|
|
105
|
+
var x2 = d[x];
|
|
106
|
+
var x4 = d[x2];
|
|
107
|
+
var x8 = d[x4];
|
|
182
108
|
|
|
109
|
+
// Compute sub bytes, mix columns tables
|
|
110
|
+
var t = (d[sx] * 0x101) ^ (sx * 0x1010100);
|
|
111
|
+
SUB_MIX_0[x] = (t << 24) | (t >>> 8);
|
|
112
|
+
SUB_MIX_1[x] = (t << 16) | (t >>> 16);
|
|
113
|
+
SUB_MIX_2[x] = (t << 8) | (t >>> 24);
|
|
114
|
+
SUB_MIX_3[x] = t;
|
|
183
115
|
|
|
116
|
+
// Compute inv sub bytes, inv mix columns tables
|
|
117
|
+
var t = (x8 * 0x1010101) ^ (x4 * 0x10001) ^ (x2 * 0x101) ^ (x * 0x1010100);
|
|
118
|
+
INV_SUB_MIX_0[sx] = (t << 24) | (t >>> 8);
|
|
119
|
+
INV_SUB_MIX_1[sx] = (t << 16) | (t >>> 16);
|
|
120
|
+
INV_SUB_MIX_2[sx] = (t << 8) | (t >>> 24);
|
|
121
|
+
INV_SUB_MIX_3[sx] = t;
|
|
184
122
|
|
|
123
|
+
// Compute next counter
|
|
124
|
+
if (!x) {
|
|
125
|
+
x = xi = 1;
|
|
126
|
+
} else {
|
|
127
|
+
x = x2 ^ d[d[d[x8 ^ x2]]];
|
|
128
|
+
xi ^= d[d[xi]];
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}());
|
|
185
132
|
|
|
133
|
+
// Precomputed Rcon lookup
|
|
134
|
+
var RCON = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36];
|
|
186
135
|
|
|
136
|
+
/**
|
|
137
|
+
* AES block cipher algorithm.
|
|
138
|
+
*/
|
|
139
|
+
var AES = C_algo.AES = BlockCipher.extend({
|
|
140
|
+
_doReset: function () {
|
|
141
|
+
var t;
|
|
187
142
|
|
|
143
|
+
// Skip reset of nRounds has been set before and key did not change
|
|
144
|
+
if (this._nRounds && this._keyPriorReset === this._key) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
188
147
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
[_constants__WEBPACK_IMPORTED_MODULE_0__["default"].EncrytionTypes.RC4]: (crypto_js_rc4__WEBPACK_IMPORTED_MODULE_5___default())
|
|
194
|
-
};
|
|
195
|
-
class SecureLS {
|
|
196
|
-
constructor({
|
|
197
|
-
encryptionSecret = '',
|
|
198
|
-
encryptionNamespace = '',
|
|
199
|
-
isCompression = true,
|
|
200
|
-
encodingType = _constants__WEBPACK_IMPORTED_MODULE_0__["default"].EncrytionTypes.BASE64,
|
|
201
|
-
storage = localStorage,
|
|
202
|
-
metaKey = _constants__WEBPACK_IMPORTED_MODULE_0__["default"].metaKey
|
|
203
|
-
} = {}) {
|
|
204
|
-
// Assign libraries and utilities
|
|
205
|
-
Object.assign(this, {
|
|
206
|
-
_name: 'secure-ls',
|
|
207
|
-
Base64: _Base64__WEBPACK_IMPORTED_MODULE_8__["default"],
|
|
208
|
-
LZString: {
|
|
209
|
-
compressToUTF16: lz_string_libs_lz_string__WEBPACK_IMPORTED_MODULE_7__.compressToUTF16,
|
|
210
|
-
decompressFromUTF16: lz_string_libs_lz_string__WEBPACK_IMPORTED_MODULE_7__.decompressFromUTF16
|
|
211
|
-
},
|
|
212
|
-
AES: (crypto_js_aes__WEBPACK_IMPORTED_MODULE_3___default()),
|
|
213
|
-
DES: (crypto_js_tripledes__WEBPACK_IMPORTED_MODULE_6___default()),
|
|
214
|
-
RABBIT: (crypto_js_rabbit__WEBPACK_IMPORTED_MODULE_4___default()),
|
|
215
|
-
RC4: (crypto_js_rc4__WEBPACK_IMPORTED_MODULE_5___default()),
|
|
216
|
-
enc: _enc_utf8__WEBPACK_IMPORTED_MODULE_1__["default"]
|
|
217
|
-
});
|
|
148
|
+
// Shortcuts
|
|
149
|
+
var key = this._keyPriorReset = this._key;
|
|
150
|
+
var keyWords = key.words;
|
|
151
|
+
var keySize = key.sigBytes / 4;
|
|
218
152
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
encryptionSecret,
|
|
222
|
-
encryptionNamespace,
|
|
223
|
-
isCompression,
|
|
224
|
-
encodingType: encodingType.toLowerCase(),
|
|
225
|
-
storage,
|
|
226
|
-
metaKey
|
|
227
|
-
};
|
|
228
|
-
this.encryptionSecret = encryptionSecret;
|
|
229
|
-
this.storage = storage;
|
|
230
|
-
this.metaKey = metaKey;
|
|
231
|
-
|
|
232
|
-
// Initialize the class
|
|
233
|
-
this.init();
|
|
234
|
-
}
|
|
235
|
-
init() {
|
|
236
|
-
let metaData = this.getMetaData();
|
|
237
|
-
this._isBase64 = this._isBase64EncryptionType();
|
|
238
|
-
this._isAES = this._isAESEncryptionType();
|
|
239
|
-
this._isDES = this._isDESEncryptionType();
|
|
240
|
-
this._isRabbit = this._isRabbitEncryptionType();
|
|
241
|
-
this._isRC4 = this._isRC4EncryptionType();
|
|
242
|
-
this._isCompression = this._isDataCompressionEnabled();
|
|
153
|
+
// Compute number of rounds
|
|
154
|
+
var nRounds = this._nRounds = keySize + 6;
|
|
243
155
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
}
|
|
247
|
-
_isBase64EncryptionType() {
|
|
248
|
-
return _Base64__WEBPACK_IMPORTED_MODULE_8__["default"] && (typeof this.config.encodingType === 'undefined' || this.config.encodingType === _constants__WEBPACK_IMPORTED_MODULE_0__["default"].EncrytionTypes.BASE64);
|
|
249
|
-
}
|
|
250
|
-
_isAESEncryptionType() {
|
|
251
|
-
return (crypto_js_aes__WEBPACK_IMPORTED_MODULE_3___default()) && this.config.encodingType === _constants__WEBPACK_IMPORTED_MODULE_0__["default"].EncrytionTypes.AES;
|
|
252
|
-
}
|
|
253
|
-
_isDESEncryptionType() {
|
|
254
|
-
return (crypto_js_tripledes__WEBPACK_IMPORTED_MODULE_6___default()) && this.config.encodingType === _constants__WEBPACK_IMPORTED_MODULE_0__["default"].EncrytionTypes.DES;
|
|
255
|
-
}
|
|
256
|
-
_isRabbitEncryptionType() {
|
|
257
|
-
return (crypto_js_rabbit__WEBPACK_IMPORTED_MODULE_4___default()) && this.config.encodingType === _constants__WEBPACK_IMPORTED_MODULE_0__["default"].EncrytionTypes.RABBIT;
|
|
258
|
-
}
|
|
259
|
-
_isRC4EncryptionType() {
|
|
260
|
-
return (crypto_js_rc4__WEBPACK_IMPORTED_MODULE_5___default()) && this.config.encodingType === _constants__WEBPACK_IMPORTED_MODULE_0__["default"].EncrytionTypes.RC4;
|
|
261
|
-
}
|
|
262
|
-
_isDataCompressionEnabled() {
|
|
263
|
-
return this.config.isCompression;
|
|
264
|
-
}
|
|
265
|
-
getEncryptionSecret(key) {
|
|
266
|
-
let metaData = this.getMetaData();
|
|
267
|
-
let obj = _utils__WEBPACK_IMPORTED_MODULE_2__["default"].getObjectFromKey(metaData.keys, key);
|
|
268
|
-
if (!obj) {
|
|
269
|
-
return;
|
|
270
|
-
}
|
|
271
|
-
if (this._isAES || this._isDES || this._isRabbit || this._isRC4) {
|
|
272
|
-
if (typeof this.config.encryptionSecret === 'undefined') {
|
|
273
|
-
this.encryptionSecret = obj.s;
|
|
274
|
-
if (!this.encryptionSecret) {
|
|
275
|
-
this.encryptionSecret = _utils__WEBPACK_IMPORTED_MODULE_2__["default"].generateSecretKey();
|
|
276
|
-
this.setMetaData();
|
|
277
|
-
}
|
|
278
|
-
} else {
|
|
279
|
-
this.encryptionSecret = this.config.encryptionSecret || obj.s || '';
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
getEncryptionType() {
|
|
284
|
-
const encodingType = this.config.encodingType;
|
|
285
|
-
return encodingType ? encodingType.toLowerCase() : _constants__WEBPACK_IMPORTED_MODULE_0__["default"].EncrytionTypes.BASE64;
|
|
286
|
-
}
|
|
287
|
-
getDataFromLocalStorage(key) {
|
|
288
|
-
return this.storage.getItem(key, true);
|
|
289
|
-
}
|
|
290
|
-
setDataToLocalStorage(key, data) {
|
|
291
|
-
this.storage.setItem(key, data);
|
|
292
|
-
}
|
|
293
|
-
setMetaData() {
|
|
294
|
-
let dataToStore = this.processData({
|
|
295
|
-
keys: this.allKeys
|
|
296
|
-
}, true);
|
|
156
|
+
// Compute number of key schedule rows
|
|
157
|
+
var ksRows = (nRounds + 1) * 4;
|
|
297
158
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
return this.metaKey + (this.config.encryptionNamespace ? '__' + this.config.encryptionNamespace : '');
|
|
306
|
-
}
|
|
307
|
-
resetAllKeys() {
|
|
308
|
-
this.allKeys = [];
|
|
309
|
-
return [];
|
|
310
|
-
}
|
|
311
|
-
processData(data, isAllKeysData) {
|
|
312
|
-
if (data === null || data === undefined || data === '') {
|
|
313
|
-
return '';
|
|
314
|
-
}
|
|
315
|
-
let jsonData;
|
|
316
|
-
try {
|
|
317
|
-
jsonData = JSON.stringify(data);
|
|
318
|
-
} catch (err) {
|
|
319
|
-
throw new Error('Could not stringify data', err);
|
|
320
|
-
}
|
|
159
|
+
// Compute key schedule
|
|
160
|
+
var keySchedule = this._keySchedule = [];
|
|
161
|
+
for (var ksRow = 0; ksRow < ksRows; ksRow++) {
|
|
162
|
+
if (ksRow < keySize) {
|
|
163
|
+
keySchedule[ksRow] = keyWords[ksRow];
|
|
164
|
+
} else {
|
|
165
|
+
t = keySchedule[ksRow - 1];
|
|
321
166
|
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
if (this._isBase64 || isAllKeysData) {
|
|
326
|
-
encodedData = _Base64__WEBPACK_IMPORTED_MODULE_8__["default"].encode(jsonData);
|
|
327
|
-
} else {
|
|
328
|
-
const encryptor = encryptors[this.getEncryptionType()];
|
|
329
|
-
if (encryptor) {
|
|
330
|
-
encodedData = encryptor.encrypt(jsonData, this.encryptionSecret);
|
|
331
|
-
}
|
|
332
|
-
encodedData = encodedData && encodedData.toString();
|
|
333
|
-
}
|
|
167
|
+
if (!(ksRow % keySize)) {
|
|
168
|
+
// Rot word
|
|
169
|
+
t = (t << 8) | (t >>> 24);
|
|
334
170
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
if (this._isCompression || isAllKeysData) {
|
|
338
|
-
compressedData = this.LZString.compressToUTF16(encodedData);
|
|
339
|
-
}
|
|
340
|
-
return compressedData;
|
|
341
|
-
}
|
|
171
|
+
// Sub word
|
|
172
|
+
t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff];
|
|
342
173
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
let decodedData = '';
|
|
350
|
-
let jsonData = '';
|
|
351
|
-
if (!_utils__WEBPACK_IMPORTED_MODULE_2__["default"].is(key)) {
|
|
352
|
-
_utils__WEBPACK_IMPORTED_MODULE_2__["default"].warn(_constants__WEBPACK_IMPORTED_MODULE_0__["default"].WarningEnum.KEY_NOT_PROVIDED);
|
|
353
|
-
return jsonData;
|
|
354
|
-
}
|
|
355
|
-
let data = this.getDataFromLocalStorage(key);
|
|
356
|
-
if (!data) {
|
|
357
|
-
return jsonData;
|
|
358
|
-
}
|
|
359
|
-
let deCompressedData = data; // saves else
|
|
360
|
-
if (this._isCompression || isAllKeysData) {
|
|
361
|
-
// meta data always compressed
|
|
362
|
-
deCompressedData = this.LZString.decompressFromUTF16(data);
|
|
363
|
-
}
|
|
364
|
-
decodedData = deCompressedData; // saves else
|
|
365
|
-
if (this._isBase64 || isAllKeysData) {
|
|
366
|
-
// meta data always Base64
|
|
367
|
-
decodedData = _Base64__WEBPACK_IMPORTED_MODULE_8__["default"].decode(deCompressedData);
|
|
368
|
-
} else {
|
|
369
|
-
this.getEncryptionSecret(key);
|
|
370
|
-
const encryptor = encryptors[this.getEncryptionType()];
|
|
371
|
-
if (encryptor) {
|
|
372
|
-
const bytes = encryptor.decrypt(deCompressedData.toString(), this.encryptionSecret);
|
|
373
|
-
if (bytes) {
|
|
374
|
-
decodedData = bytes.toString(_enc_utf8__WEBPACK_IMPORTED_MODULE_1__["default"]._Utf8);
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
try {
|
|
379
|
-
jsonData = JSON.parse(decodedData);
|
|
380
|
-
} catch (err) {
|
|
381
|
-
throw new Error('Could not parse JSON', err);
|
|
382
|
-
}
|
|
383
|
-
return jsonData;
|
|
384
|
-
}
|
|
385
|
-
set(key, data) {
|
|
386
|
-
let dataToStore = '';
|
|
387
|
-
if (!_utils__WEBPACK_IMPORTED_MODULE_2__["default"].is(key)) {
|
|
388
|
-
_utils__WEBPACK_IMPORTED_MODULE_2__["default"].warn(_constants__WEBPACK_IMPORTED_MODULE_0__["default"].WarningEnum.KEY_NOT_PROVIDED);
|
|
389
|
-
return;
|
|
390
|
-
}
|
|
391
|
-
this.getEncryptionSecret(key);
|
|
174
|
+
// Mix Rcon
|
|
175
|
+
t ^= RCON[(ksRow / keySize) | 0] << 24;
|
|
176
|
+
} else if (keySize > 6 && ksRow % keySize == 4) {
|
|
177
|
+
// Sub word
|
|
178
|
+
t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff];
|
|
179
|
+
}
|
|
392
180
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
this.allKeys.push({
|
|
397
|
-
k: key,
|
|
398
|
-
s: this.encryptionSecret
|
|
399
|
-
});
|
|
400
|
-
this.setMetaData();
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
dataToStore = this.processData(data);
|
|
404
|
-
// Store the data to localStorage
|
|
405
|
-
this.setDataToLocalStorage(key, dataToStore);
|
|
406
|
-
}
|
|
407
|
-
remove(key) {
|
|
408
|
-
if (!_utils__WEBPACK_IMPORTED_MODULE_2__["default"].is(key)) {
|
|
409
|
-
_utils__WEBPACK_IMPORTED_MODULE_2__["default"].warn(_constants__WEBPACK_IMPORTED_MODULE_0__["default"].WarningEnum.KEY_NOT_PROVIDED);
|
|
410
|
-
return;
|
|
411
|
-
}
|
|
412
|
-
if (key === this.metaKey && this.getAllKeys().length) {
|
|
413
|
-
_utils__WEBPACK_IMPORTED_MODULE_2__["default"].warn(_constants__WEBPACK_IMPORTED_MODULE_0__["default"].WarningEnum.META_KEY_REMOVE);
|
|
414
|
-
return;
|
|
415
|
-
}
|
|
416
|
-
if (_utils__WEBPACK_IMPORTED_MODULE_2__["default"].isKeyPresent(this.allKeys, key)) {
|
|
417
|
-
_utils__WEBPACK_IMPORTED_MODULE_2__["default"].removeFromKeysList(this.allKeys, key);
|
|
418
|
-
this.setMetaData();
|
|
419
|
-
}
|
|
420
|
-
this.storage.removeItem(key);
|
|
421
|
-
}
|
|
422
|
-
removeAll() {
|
|
423
|
-
let keys = this.getAllKeys();
|
|
424
|
-
for (let i = 0; i < keys.length; i++) {
|
|
425
|
-
this.storage.removeItem(keys[i]);
|
|
426
|
-
}
|
|
427
|
-
this.storage.removeItem(this.metaKey);
|
|
428
|
-
this.resetAllKeys();
|
|
429
|
-
}
|
|
430
|
-
clear() {
|
|
431
|
-
this.storage.clear();
|
|
432
|
-
this.resetAllKeys();
|
|
433
|
-
}
|
|
434
|
-
}
|
|
181
|
+
keySchedule[ksRow] = keySchedule[ksRow - keySize] ^ t;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
435
184
|
|
|
436
|
-
|
|
185
|
+
// Compute inv key schedule
|
|
186
|
+
var invKeySchedule = this._invKeySchedule = [];
|
|
187
|
+
for (var invKsRow = 0; invKsRow < ksRows; invKsRow++) {
|
|
188
|
+
var ksRow = ksRows - invKsRow;
|
|
437
189
|
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
190
|
+
if (invKsRow % 4) {
|
|
191
|
+
var t = keySchedule[ksRow];
|
|
192
|
+
} else {
|
|
193
|
+
var t = keySchedule[ksRow - 4];
|
|
194
|
+
}
|
|
443
195
|
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
196
|
+
if (invKsRow < 4 || ksRow <= 4) {
|
|
197
|
+
invKeySchedule[invKsRow] = t;
|
|
198
|
+
} else {
|
|
199
|
+
invKeySchedule[invKsRow] = INV_SUB_MIX_0[SBOX[t >>> 24]] ^ INV_SUB_MIX_1[SBOX[(t >>> 16) & 0xff]] ^
|
|
200
|
+
INV_SUB_MIX_2[SBOX[(t >>> 8) & 0xff]] ^ INV_SUB_MIX_3[SBOX[t & 0xff]];
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
},
|
|
451
204
|
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
205
|
+
encryptBlock: function (M, offset) {
|
|
206
|
+
this._doCryptBlock(M, offset, this._keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX);
|
|
207
|
+
},
|
|
455
208
|
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
let mask = 0xffffffff;
|
|
462
|
-
return function () {
|
|
463
|
-
mz = 0x9069 * (mz & 0xffff) + (mz >> 0x10) & mask;
|
|
464
|
-
mw = 0x4650 * (mw & 0xffff) + (mw >> 0x10) & mask;
|
|
465
|
-
let result = (mz << 0x10) + mw & mask;
|
|
466
|
-
result /= 0x100000000;
|
|
467
|
-
result += 0.5;
|
|
468
|
-
return result * (Math.random() > 0.5 ? 1 : -1);
|
|
469
|
-
};
|
|
470
|
-
};
|
|
471
|
-
for (let i = 0, rcache; i < nBytes; i += 4) {
|
|
472
|
-
let _r = r((rcache || Math.random()) * 0x100000000);
|
|
473
|
-
rcache = _r() * 0x3ade67b7;
|
|
474
|
-
words.push(_r() * 0x100000000 | 0);
|
|
475
|
-
}
|
|
476
|
-
return new CryptoJSWordArray.Set(words, nBytes);
|
|
477
|
-
},
|
|
478
|
-
Set: function (words, sigBytes) {
|
|
479
|
-
words = this.words = words || [];
|
|
480
|
-
if (sigBytes !== undefined) {
|
|
481
|
-
this.sigBytes = sigBytes;
|
|
482
|
-
} else {
|
|
483
|
-
this.sigBytes = words.length * 8;
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
};
|
|
487
|
-
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (CryptoJSWordArray);
|
|
209
|
+
decryptBlock: function (M, offset) {
|
|
210
|
+
// Swap 2nd and 4th rows
|
|
211
|
+
var t = M[offset + 1];
|
|
212
|
+
M[offset + 1] = M[offset + 3];
|
|
213
|
+
M[offset + 3] = t;
|
|
488
214
|
|
|
489
|
-
|
|
215
|
+
this._doCryptBlock(M, offset, this._invKeySchedule, INV_SUB_MIX_0, INV_SUB_MIX_1, INV_SUB_MIX_2, INV_SUB_MIX_3, INV_SBOX);
|
|
490
216
|
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
217
|
+
// Inv swap 2nd and 4th rows
|
|
218
|
+
var t = M[offset + 1];
|
|
219
|
+
M[offset + 1] = M[offset + 3];
|
|
220
|
+
M[offset + 3] = t;
|
|
221
|
+
},
|
|
496
222
|
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
|
|
501
|
-
/* harmony export */ });
|
|
502
|
-
const WarningEnum = {
|
|
503
|
-
KEY_NOT_PROVIDED: 'keyNotProvided',
|
|
504
|
-
META_KEY_REMOVE: 'metaKeyRemove',
|
|
505
|
-
DEFAULT_TEXT: 'defaultText'
|
|
506
|
-
};
|
|
507
|
-
const WarningTypes = {};
|
|
508
|
-
WarningTypes[WarningEnum.KEY_NOT_PROVIDED] = 'Secure LS: Key not provided. Aborting operation!';
|
|
509
|
-
WarningTypes[WarningEnum.META_KEY_REMOVE] = `Secure LS: Meta key can not be removed
|
|
510
|
-
unless all keys created by Secure LS are removed!`;
|
|
511
|
-
WarningTypes[WarningEnum.DEFAULT_TEXT] = `Unexpected output`;
|
|
512
|
-
const constants = {
|
|
513
|
-
WarningEnum: WarningEnum,
|
|
514
|
-
WarningTypes: WarningTypes,
|
|
515
|
-
EncrytionTypes: {
|
|
516
|
-
BASE64: 'base64',
|
|
517
|
-
AES: 'aes',
|
|
518
|
-
DES: 'des',
|
|
519
|
-
RABBIT: 'rabbit',
|
|
520
|
-
RC4: 'rc4'
|
|
521
|
-
},
|
|
522
|
-
metaKey: '_secure__ls__metadata',
|
|
523
|
-
secretPhrase: 's3cr3t$#@135^&*246'
|
|
524
|
-
};
|
|
525
|
-
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (constants);
|
|
223
|
+
_doCryptBlock: function (M, offset, keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX) {
|
|
224
|
+
// Shortcut
|
|
225
|
+
var nRounds = this._nRounds;
|
|
526
226
|
|
|
527
|
-
|
|
227
|
+
// Get input, add round key
|
|
228
|
+
var s0 = M[offset] ^ keySchedule[0];
|
|
229
|
+
var s1 = M[offset + 1] ^ keySchedule[1];
|
|
230
|
+
var s2 = M[offset + 2] ^ keySchedule[2];
|
|
231
|
+
var s3 = M[offset + 3] ^ keySchedule[3];
|
|
528
232
|
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
!*** ./src/enc-utf8.js ***!
|
|
532
|
-
\*************************/
|
|
533
|
-
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
233
|
+
// Key schedule row counter
|
|
234
|
+
var ksRow = 4;
|
|
534
235
|
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
236
|
+
// Rounds
|
|
237
|
+
for (var round = 1; round < nRounds; round++) {
|
|
238
|
+
// Shift rows, sub bytes, mix columns, add round key
|
|
239
|
+
var t0 = SUB_MIX_0[s0 >>> 24] ^ SUB_MIX_1[(s1 >>> 16) & 0xff] ^ SUB_MIX_2[(s2 >>> 8) & 0xff] ^ SUB_MIX_3[s3 & 0xff] ^ keySchedule[ksRow++];
|
|
240
|
+
var t1 = SUB_MIX_0[s1 >>> 24] ^ SUB_MIX_1[(s2 >>> 16) & 0xff] ^ SUB_MIX_2[(s3 >>> 8) & 0xff] ^ SUB_MIX_3[s0 & 0xff] ^ keySchedule[ksRow++];
|
|
241
|
+
var t2 = SUB_MIX_0[s2 >>> 24] ^ SUB_MIX_1[(s3 >>> 16) & 0xff] ^ SUB_MIX_2[(s0 >>> 8) & 0xff] ^ SUB_MIX_3[s1 & 0xff] ^ keySchedule[ksRow++];
|
|
242
|
+
var t3 = SUB_MIX_0[s3 >>> 24] ^ SUB_MIX_1[(s0 >>> 16) & 0xff] ^ SUB_MIX_2[(s1 >>> 8) & 0xff] ^ SUB_MIX_3[s2 & 0xff] ^ keySchedule[ksRow++];
|
|
542
243
|
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
// Shortcuts
|
|
550
|
-
let words = wordArray.words;
|
|
551
|
-
let sigBytes = wordArray.sigBytes;
|
|
552
|
-
let latin1Chars = [],
|
|
553
|
-
i,
|
|
554
|
-
bite;
|
|
244
|
+
// Update state
|
|
245
|
+
s0 = t0;
|
|
246
|
+
s1 = t1;
|
|
247
|
+
s2 = t2;
|
|
248
|
+
s3 = t3;
|
|
249
|
+
}
|
|
555
250
|
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
return latin1Chars.join('');
|
|
562
|
-
}
|
|
563
|
-
},
|
|
564
|
-
_Utf8: {
|
|
565
|
-
stringify: wordArray => {
|
|
566
|
-
try {
|
|
567
|
-
return decodeURIComponent(escape(enc.Latin1.stringify(wordArray)));
|
|
568
|
-
} catch (err) {
|
|
569
|
-
throw new Error('Malformed UTF-8 data', err);
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
};
|
|
574
|
-
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (enc);
|
|
251
|
+
// Shift rows, sub bytes, add round key
|
|
252
|
+
var t0 = ((SBOX[s0 >>> 24] << 24) | (SBOX[(s1 >>> 16) & 0xff] << 16) | (SBOX[(s2 >>> 8) & 0xff] << 8) | SBOX[s3 & 0xff]) ^ keySchedule[ksRow++];
|
|
253
|
+
var t1 = ((SBOX[s1 >>> 24] << 24) | (SBOX[(s2 >>> 16) & 0xff] << 16) | (SBOX[(s3 >>> 8) & 0xff] << 8) | SBOX[s0 & 0xff]) ^ keySchedule[ksRow++];
|
|
254
|
+
var t2 = ((SBOX[s2 >>> 24] << 24) | (SBOX[(s3 >>> 16) & 0xff] << 16) | (SBOX[(s0 >>> 8) & 0xff] << 8) | SBOX[s1 & 0xff]) ^ keySchedule[ksRow++];
|
|
255
|
+
var t3 = ((SBOX[s3 >>> 24] << 24) | (SBOX[(s0 >>> 16) & 0xff] << 16) | (SBOX[(s1 >>> 8) & 0xff] << 8) | SBOX[s2 & 0xff]) ^ keySchedule[ksRow++];
|
|
575
256
|
|
|
576
|
-
|
|
257
|
+
// Set output
|
|
258
|
+
M[offset] = t0;
|
|
259
|
+
M[offset + 1] = t1;
|
|
260
|
+
M[offset + 2] = t2;
|
|
261
|
+
M[offset + 3] = t3;
|
|
262
|
+
},
|
|
577
263
|
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
!*** ./src/utils.js ***!
|
|
581
|
-
\**********************/
|
|
582
|
-
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
264
|
+
keySize: 256/32
|
|
265
|
+
});
|
|
583
266
|
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
267
|
+
/**
|
|
268
|
+
* Shortcut functions to the cipher's object interface.
|
|
269
|
+
*
|
|
270
|
+
* @example
|
|
271
|
+
*
|
|
272
|
+
* var ciphertext = CryptoJS.AES.encrypt(message, key, cfg);
|
|
273
|
+
* var plaintext = CryptoJS.AES.decrypt(ciphertext, key, cfg);
|
|
274
|
+
*/
|
|
275
|
+
C.AES = BlockCipher._createHelper(AES);
|
|
276
|
+
}());
|
|
593
277
|
|
|
594
278
|
|
|
279
|
+
return CryptoJS.AES;
|
|
595
280
|
|
|
596
|
-
|
|
597
|
-
is: key => !!key,
|
|
598
|
-
warn: (reason = _constants__WEBPACK_IMPORTED_MODULE_1__["default"].WarningEnum.DEFAULT_TEXT) => {
|
|
599
|
-
console.warn(_constants__WEBPACK_IMPORTED_MODULE_1__["default"].WarningTypes[reason]);
|
|
600
|
-
},
|
|
601
|
-
generateSecretKey: () => {
|
|
602
|
-
const salt = _WordArray__WEBPACK_IMPORTED_MODULE_2__["default"].random(128 / 8);
|
|
603
|
-
const key128Bits = crypto_js_pbkdf2__WEBPACK_IMPORTED_MODULE_0___default()(_constants__WEBPACK_IMPORTED_MODULE_1__["default"].secretPhrase, salt, {
|
|
604
|
-
keySize: 128 / 32
|
|
605
|
-
});
|
|
606
|
-
return key128Bits.toString();
|
|
607
|
-
},
|
|
608
|
-
getObjectFromKey: (data = [], key) => {
|
|
609
|
-
return data.find(item => item.k === key) || {};
|
|
610
|
-
},
|
|
611
|
-
extractKeyNames: ({
|
|
612
|
-
keys = []
|
|
613
|
-
} = {}) => {
|
|
614
|
-
return keys.map(({
|
|
615
|
-
k
|
|
616
|
-
}) => k);
|
|
617
|
-
},
|
|
618
|
-
isKeyPresent: (allKeys = [], key) => {
|
|
619
|
-
return allKeys.some(item => String(item.k) === String(key));
|
|
620
|
-
},
|
|
621
|
-
removeFromKeysList: (allKeys = [], key) => {
|
|
622
|
-
const index = allKeys.findIndex(item => item.k === key);
|
|
623
|
-
if (index !== -1) {
|
|
624
|
-
allKeys.splice(index, 1);
|
|
625
|
-
}
|
|
626
|
-
return index;
|
|
627
|
-
}
|
|
628
|
-
};
|
|
629
|
-
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (utils);
|
|
281
|
+
}));
|
|
630
282
|
|
|
631
283
|
/***/ }),
|
|
632
284
|
|
|
633
|
-
/***/ "./node_modules/crypto-js/
|
|
634
|
-
|
|
635
|
-
!*** ./node_modules/crypto-js/
|
|
636
|
-
|
|
285
|
+
/***/ "./node_modules/crypto-js/cipher-core.js":
|
|
286
|
+
/*!***********************************************!*\
|
|
287
|
+
!*** ./node_modules/crypto-js/cipher-core.js ***!
|
|
288
|
+
\***********************************************/
|
|
637
289
|
/***/ (function(module, exports, __webpack_require__) {
|
|
638
290
|
|
|
639
291
|
;(function (root, factory, undef) {
|
|
640
292
|
if (true) {
|
|
641
293
|
// CommonJS
|
|
642
|
-
module.exports = exports = factory(__webpack_require__(/*! ./core */ "./node_modules/crypto-js/core.js"), __webpack_require__(/*! ./
|
|
294
|
+
module.exports = exports = factory(__webpack_require__(/*! ./core */ "./node_modules/crypto-js/core.js"), __webpack_require__(/*! ./evpkdf */ "./node_modules/crypto-js/evpkdf.js"));
|
|
643
295
|
}
|
|
644
296
|
else {}
|
|
645
297
|
}(this, function (CryptoJS) {
|
|
646
298
|
|
|
647
|
-
|
|
299
|
+
/**
|
|
300
|
+
* Cipher core components.
|
|
301
|
+
*/
|
|
302
|
+
CryptoJS.lib.Cipher || (function (undefined) {
|
|
648
303
|
// Shortcuts
|
|
649
304
|
var C = CryptoJS;
|
|
650
305
|
var C_lib = C.lib;
|
|
651
|
-
var
|
|
306
|
+
var Base = C_lib.Base;
|
|
307
|
+
var WordArray = C_lib.WordArray;
|
|
308
|
+
var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm;
|
|
309
|
+
var C_enc = C.enc;
|
|
310
|
+
var Utf8 = C_enc.Utf8;
|
|
311
|
+
var Base64 = C_enc.Base64;
|
|
652
312
|
var C_algo = C.algo;
|
|
653
|
-
|
|
654
|
-
// Lookup tables
|
|
655
|
-
var SBOX = [];
|
|
656
|
-
var INV_SBOX = [];
|
|
657
|
-
var SUB_MIX_0 = [];
|
|
658
|
-
var SUB_MIX_1 = [];
|
|
659
|
-
var SUB_MIX_2 = [];
|
|
660
|
-
var SUB_MIX_3 = [];
|
|
661
|
-
var INV_SUB_MIX_0 = [];
|
|
662
|
-
var INV_SUB_MIX_1 = [];
|
|
663
|
-
var INV_SUB_MIX_2 = [];
|
|
664
|
-
var INV_SUB_MIX_3 = [];
|
|
665
|
-
|
|
666
|
-
// Compute lookup tables
|
|
667
|
-
(function () {
|
|
668
|
-
// Compute double table
|
|
669
|
-
var d = [];
|
|
670
|
-
for (var i = 0; i < 256; i++) {
|
|
671
|
-
if (i < 128) {
|
|
672
|
-
d[i] = i << 1;
|
|
673
|
-
} else {
|
|
674
|
-
d[i] = (i << 1) ^ 0x11b;
|
|
675
|
-
}
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
// Walk GF(2^8)
|
|
679
|
-
var x = 0;
|
|
680
|
-
var xi = 0;
|
|
681
|
-
for (var i = 0; i < 256; i++) {
|
|
682
|
-
// Compute sbox
|
|
683
|
-
var sx = xi ^ (xi << 1) ^ (xi << 2) ^ (xi << 3) ^ (xi << 4);
|
|
684
|
-
sx = (sx >>> 8) ^ (sx & 0xff) ^ 0x63;
|
|
685
|
-
SBOX[x] = sx;
|
|
686
|
-
INV_SBOX[sx] = x;
|
|
687
|
-
|
|
688
|
-
// Compute multiplication
|
|
689
|
-
var x2 = d[x];
|
|
690
|
-
var x4 = d[x2];
|
|
691
|
-
var x8 = d[x4];
|
|
692
|
-
|
|
693
|
-
// Compute sub bytes, mix columns tables
|
|
694
|
-
var t = (d[sx] * 0x101) ^ (sx * 0x1010100);
|
|
695
|
-
SUB_MIX_0[x] = (t << 24) | (t >>> 8);
|
|
696
|
-
SUB_MIX_1[x] = (t << 16) | (t >>> 16);
|
|
697
|
-
SUB_MIX_2[x] = (t << 8) | (t >>> 24);
|
|
698
|
-
SUB_MIX_3[x] = t;
|
|
699
|
-
|
|
700
|
-
// Compute inv sub bytes, inv mix columns tables
|
|
701
|
-
var t = (x8 * 0x1010101) ^ (x4 * 0x10001) ^ (x2 * 0x101) ^ (x * 0x1010100);
|
|
702
|
-
INV_SUB_MIX_0[sx] = (t << 24) | (t >>> 8);
|
|
703
|
-
INV_SUB_MIX_1[sx] = (t << 16) | (t >>> 16);
|
|
704
|
-
INV_SUB_MIX_2[sx] = (t << 8) | (t >>> 24);
|
|
705
|
-
INV_SUB_MIX_3[sx] = t;
|
|
706
|
-
|
|
707
|
-
// Compute next counter
|
|
708
|
-
if (!x) {
|
|
709
|
-
x = xi = 1;
|
|
710
|
-
} else {
|
|
711
|
-
x = x2 ^ d[d[d[x8 ^ x2]]];
|
|
712
|
-
xi ^= d[d[xi]];
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
}());
|
|
716
|
-
|
|
717
|
-
// Precomputed Rcon lookup
|
|
718
|
-
var RCON = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36];
|
|
719
|
-
|
|
720
|
-
/**
|
|
721
|
-
* AES block cipher algorithm.
|
|
722
|
-
*/
|
|
723
|
-
var AES = C_algo.AES = BlockCipher.extend({
|
|
724
|
-
_doReset: function () {
|
|
725
|
-
var t;
|
|
726
|
-
|
|
727
|
-
// Skip reset of nRounds has been set before and key did not change
|
|
728
|
-
if (this._nRounds && this._keyPriorReset === this._key) {
|
|
729
|
-
return;
|
|
730
|
-
}
|
|
731
|
-
|
|
732
|
-
// Shortcuts
|
|
733
|
-
var key = this._keyPriorReset = this._key;
|
|
734
|
-
var keyWords = key.words;
|
|
735
|
-
var keySize = key.sigBytes / 4;
|
|
736
|
-
|
|
737
|
-
// Compute number of rounds
|
|
738
|
-
var nRounds = this._nRounds = keySize + 6;
|
|
739
|
-
|
|
740
|
-
// Compute number of key schedule rows
|
|
741
|
-
var ksRows = (nRounds + 1) * 4;
|
|
742
|
-
|
|
743
|
-
// Compute key schedule
|
|
744
|
-
var keySchedule = this._keySchedule = [];
|
|
745
|
-
for (var ksRow = 0; ksRow < ksRows; ksRow++) {
|
|
746
|
-
if (ksRow < keySize) {
|
|
747
|
-
keySchedule[ksRow] = keyWords[ksRow];
|
|
748
|
-
} else {
|
|
749
|
-
t = keySchedule[ksRow - 1];
|
|
750
|
-
|
|
751
|
-
if (!(ksRow % keySize)) {
|
|
752
|
-
// Rot word
|
|
753
|
-
t = (t << 8) | (t >>> 24);
|
|
754
|
-
|
|
755
|
-
// Sub word
|
|
756
|
-
t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff];
|
|
757
|
-
|
|
758
|
-
// Mix Rcon
|
|
759
|
-
t ^= RCON[(ksRow / keySize) | 0] << 24;
|
|
760
|
-
} else if (keySize > 6 && ksRow % keySize == 4) {
|
|
761
|
-
// Sub word
|
|
762
|
-
t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff];
|
|
763
|
-
}
|
|
764
|
-
|
|
765
|
-
keySchedule[ksRow] = keySchedule[ksRow - keySize] ^ t;
|
|
766
|
-
}
|
|
767
|
-
}
|
|
768
|
-
|
|
769
|
-
// Compute inv key schedule
|
|
770
|
-
var invKeySchedule = this._invKeySchedule = [];
|
|
771
|
-
for (var invKsRow = 0; invKsRow < ksRows; invKsRow++) {
|
|
772
|
-
var ksRow = ksRows - invKsRow;
|
|
773
|
-
|
|
774
|
-
if (invKsRow % 4) {
|
|
775
|
-
var t = keySchedule[ksRow];
|
|
776
|
-
} else {
|
|
777
|
-
var t = keySchedule[ksRow - 4];
|
|
778
|
-
}
|
|
779
|
-
|
|
780
|
-
if (invKsRow < 4 || ksRow <= 4) {
|
|
781
|
-
invKeySchedule[invKsRow] = t;
|
|
782
|
-
} else {
|
|
783
|
-
invKeySchedule[invKsRow] = INV_SUB_MIX_0[SBOX[t >>> 24]] ^ INV_SUB_MIX_1[SBOX[(t >>> 16) & 0xff]] ^
|
|
784
|
-
INV_SUB_MIX_2[SBOX[(t >>> 8) & 0xff]] ^ INV_SUB_MIX_3[SBOX[t & 0xff]];
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
},
|
|
788
|
-
|
|
789
|
-
encryptBlock: function (M, offset) {
|
|
790
|
-
this._doCryptBlock(M, offset, this._keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX);
|
|
791
|
-
},
|
|
792
|
-
|
|
793
|
-
decryptBlock: function (M, offset) {
|
|
794
|
-
// Swap 2nd and 4th rows
|
|
795
|
-
var t = M[offset + 1];
|
|
796
|
-
M[offset + 1] = M[offset + 3];
|
|
797
|
-
M[offset + 3] = t;
|
|
798
|
-
|
|
799
|
-
this._doCryptBlock(M, offset, this._invKeySchedule, INV_SUB_MIX_0, INV_SUB_MIX_1, INV_SUB_MIX_2, INV_SUB_MIX_3, INV_SBOX);
|
|
800
|
-
|
|
801
|
-
// Inv swap 2nd and 4th rows
|
|
802
|
-
var t = M[offset + 1];
|
|
803
|
-
M[offset + 1] = M[offset + 3];
|
|
804
|
-
M[offset + 3] = t;
|
|
805
|
-
},
|
|
806
|
-
|
|
807
|
-
_doCryptBlock: function (M, offset, keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX) {
|
|
808
|
-
// Shortcut
|
|
809
|
-
var nRounds = this._nRounds;
|
|
810
|
-
|
|
811
|
-
// Get input, add round key
|
|
812
|
-
var s0 = M[offset] ^ keySchedule[0];
|
|
813
|
-
var s1 = M[offset + 1] ^ keySchedule[1];
|
|
814
|
-
var s2 = M[offset + 2] ^ keySchedule[2];
|
|
815
|
-
var s3 = M[offset + 3] ^ keySchedule[3];
|
|
816
|
-
|
|
817
|
-
// Key schedule row counter
|
|
818
|
-
var ksRow = 4;
|
|
819
|
-
|
|
820
|
-
// Rounds
|
|
821
|
-
for (var round = 1; round < nRounds; round++) {
|
|
822
|
-
// Shift rows, sub bytes, mix columns, add round key
|
|
823
|
-
var t0 = SUB_MIX_0[s0 >>> 24] ^ SUB_MIX_1[(s1 >>> 16) & 0xff] ^ SUB_MIX_2[(s2 >>> 8) & 0xff] ^ SUB_MIX_3[s3 & 0xff] ^ keySchedule[ksRow++];
|
|
824
|
-
var t1 = SUB_MIX_0[s1 >>> 24] ^ SUB_MIX_1[(s2 >>> 16) & 0xff] ^ SUB_MIX_2[(s3 >>> 8) & 0xff] ^ SUB_MIX_3[s0 & 0xff] ^ keySchedule[ksRow++];
|
|
825
|
-
var t2 = SUB_MIX_0[s2 >>> 24] ^ SUB_MIX_1[(s3 >>> 16) & 0xff] ^ SUB_MIX_2[(s0 >>> 8) & 0xff] ^ SUB_MIX_3[s1 & 0xff] ^ keySchedule[ksRow++];
|
|
826
|
-
var t3 = SUB_MIX_0[s3 >>> 24] ^ SUB_MIX_1[(s0 >>> 16) & 0xff] ^ SUB_MIX_2[(s1 >>> 8) & 0xff] ^ SUB_MIX_3[s2 & 0xff] ^ keySchedule[ksRow++];
|
|
827
|
-
|
|
828
|
-
// Update state
|
|
829
|
-
s0 = t0;
|
|
830
|
-
s1 = t1;
|
|
831
|
-
s2 = t2;
|
|
832
|
-
s3 = t3;
|
|
833
|
-
}
|
|
834
|
-
|
|
835
|
-
// Shift rows, sub bytes, add round key
|
|
836
|
-
var t0 = ((SBOX[s0 >>> 24] << 24) | (SBOX[(s1 >>> 16) & 0xff] << 16) | (SBOX[(s2 >>> 8) & 0xff] << 8) | SBOX[s3 & 0xff]) ^ keySchedule[ksRow++];
|
|
837
|
-
var t1 = ((SBOX[s1 >>> 24] << 24) | (SBOX[(s2 >>> 16) & 0xff] << 16) | (SBOX[(s3 >>> 8) & 0xff] << 8) | SBOX[s0 & 0xff]) ^ keySchedule[ksRow++];
|
|
838
|
-
var t2 = ((SBOX[s2 >>> 24] << 24) | (SBOX[(s3 >>> 16) & 0xff] << 16) | (SBOX[(s0 >>> 8) & 0xff] << 8) | SBOX[s1 & 0xff]) ^ keySchedule[ksRow++];
|
|
839
|
-
var t3 = ((SBOX[s3 >>> 24] << 24) | (SBOX[(s0 >>> 16) & 0xff] << 16) | (SBOX[(s1 >>> 8) & 0xff] << 8) | SBOX[s2 & 0xff]) ^ keySchedule[ksRow++];
|
|
840
|
-
|
|
841
|
-
// Set output
|
|
842
|
-
M[offset] = t0;
|
|
843
|
-
M[offset + 1] = t1;
|
|
844
|
-
M[offset + 2] = t2;
|
|
845
|
-
M[offset + 3] = t3;
|
|
846
|
-
},
|
|
847
|
-
|
|
848
|
-
keySize: 256/32
|
|
849
|
-
});
|
|
850
|
-
|
|
851
|
-
/**
|
|
852
|
-
* Shortcut functions to the cipher's object interface.
|
|
853
|
-
*
|
|
854
|
-
* @example
|
|
855
|
-
*
|
|
856
|
-
* var ciphertext = CryptoJS.AES.encrypt(message, key, cfg);
|
|
857
|
-
* var plaintext = CryptoJS.AES.decrypt(ciphertext, key, cfg);
|
|
858
|
-
*/
|
|
859
|
-
C.AES = BlockCipher._createHelper(AES);
|
|
860
|
-
}());
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
return CryptoJS.AES;
|
|
864
|
-
|
|
865
|
-
}));
|
|
866
|
-
|
|
867
|
-
/***/ }),
|
|
868
|
-
|
|
869
|
-
/***/ "./node_modules/crypto-js/cipher-core.js":
|
|
870
|
-
/*!***********************************************!*\
|
|
871
|
-
!*** ./node_modules/crypto-js/cipher-core.js ***!
|
|
872
|
-
\***********************************************/
|
|
873
|
-
/***/ (function(module, exports, __webpack_require__) {
|
|
874
|
-
|
|
875
|
-
;(function (root, factory, undef) {
|
|
876
|
-
if (true) {
|
|
877
|
-
// CommonJS
|
|
878
|
-
module.exports = exports = factory(__webpack_require__(/*! ./core */ "./node_modules/crypto-js/core.js"), __webpack_require__(/*! ./evpkdf */ "./node_modules/crypto-js/evpkdf.js"));
|
|
879
|
-
}
|
|
880
|
-
else {}
|
|
881
|
-
}(this, function (CryptoJS) {
|
|
882
|
-
|
|
883
|
-
/**
|
|
884
|
-
* Cipher core components.
|
|
885
|
-
*/
|
|
886
|
-
CryptoJS.lib.Cipher || (function (undefined) {
|
|
887
|
-
// Shortcuts
|
|
888
|
-
var C = CryptoJS;
|
|
889
|
-
var C_lib = C.lib;
|
|
890
|
-
var Base = C_lib.Base;
|
|
891
|
-
var WordArray = C_lib.WordArray;
|
|
892
|
-
var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm;
|
|
893
|
-
var C_enc = C.enc;
|
|
894
|
-
var Utf8 = C_enc.Utf8;
|
|
895
|
-
var Base64 = C_enc.Base64;
|
|
896
|
-
var C_algo = C.algo;
|
|
897
|
-
var EvpKDF = C_algo.EvpKDF;
|
|
313
|
+
var EvpKDF = C_algo.EvpKDF;
|
|
898
314
|
|
|
899
315
|
/**
|
|
900
316
|
* Abstract base cipher template.
|
|
@@ -5175,215 +4591,799 @@ var LZString = {
|
|
|
5175
4591
|
|
|
5176
4592
|
|
|
5177
4593
|
}
|
|
5178
|
-
context_enlargeIn--;
|
|
5179
|
-
if (context_enlargeIn == 0) {
|
|
5180
|
-
context_enlargeIn = Math.pow(2, context_numBits);
|
|
5181
|
-
context_numBits++;
|
|
5182
|
-
}
|
|
4594
|
+
context_enlargeIn--;
|
|
4595
|
+
if (context_enlargeIn == 0) {
|
|
4596
|
+
context_enlargeIn = Math.pow(2, context_numBits);
|
|
4597
|
+
context_numBits++;
|
|
4598
|
+
}
|
|
4599
|
+
}
|
|
4600
|
+
|
|
4601
|
+
// Mark the end of the stream
|
|
4602
|
+
value = 2;
|
|
4603
|
+
for (i=0 ; i<context_numBits ; i++) {
|
|
4604
|
+
context_data_val = (context_data_val << 1) | (value&1);
|
|
4605
|
+
if (context_data_position == bitsPerChar-1) {
|
|
4606
|
+
context_data_position = 0;
|
|
4607
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
4608
|
+
context_data_val = 0;
|
|
4609
|
+
} else {
|
|
4610
|
+
context_data_position++;
|
|
4611
|
+
}
|
|
4612
|
+
value = value >> 1;
|
|
4613
|
+
}
|
|
4614
|
+
|
|
4615
|
+
// Flush the last char
|
|
4616
|
+
while (true) {
|
|
4617
|
+
context_data_val = (context_data_val << 1);
|
|
4618
|
+
if (context_data_position == bitsPerChar-1) {
|
|
4619
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
4620
|
+
break;
|
|
4621
|
+
}
|
|
4622
|
+
else context_data_position++;
|
|
4623
|
+
}
|
|
4624
|
+
return context_data.join('');
|
|
4625
|
+
},
|
|
4626
|
+
|
|
4627
|
+
decompress: function (compressed) {
|
|
4628
|
+
if (compressed == null) return "";
|
|
4629
|
+
if (compressed == "") return null;
|
|
4630
|
+
return LZString._decompress(compressed.length, 32768, function(index) { return compressed.charCodeAt(index); });
|
|
4631
|
+
},
|
|
4632
|
+
|
|
4633
|
+
_decompress: function (length, resetValue, getNextValue) {
|
|
4634
|
+
var dictionary = [],
|
|
4635
|
+
next,
|
|
4636
|
+
enlargeIn = 4,
|
|
4637
|
+
dictSize = 4,
|
|
4638
|
+
numBits = 3,
|
|
4639
|
+
entry = "",
|
|
4640
|
+
result = [],
|
|
4641
|
+
i,
|
|
4642
|
+
w,
|
|
4643
|
+
bits, resb, maxpower, power,
|
|
4644
|
+
c,
|
|
4645
|
+
data = {val:getNextValue(0), position:resetValue, index:1};
|
|
4646
|
+
|
|
4647
|
+
for (i = 0; i < 3; i += 1) {
|
|
4648
|
+
dictionary[i] = i;
|
|
4649
|
+
}
|
|
4650
|
+
|
|
4651
|
+
bits = 0;
|
|
4652
|
+
maxpower = Math.pow(2,2);
|
|
4653
|
+
power=1;
|
|
4654
|
+
while (power!=maxpower) {
|
|
4655
|
+
resb = data.val & data.position;
|
|
4656
|
+
data.position >>= 1;
|
|
4657
|
+
if (data.position == 0) {
|
|
4658
|
+
data.position = resetValue;
|
|
4659
|
+
data.val = getNextValue(data.index++);
|
|
4660
|
+
}
|
|
4661
|
+
bits |= (resb>0 ? 1 : 0) * power;
|
|
4662
|
+
power <<= 1;
|
|
4663
|
+
}
|
|
4664
|
+
|
|
4665
|
+
switch (next = bits) {
|
|
4666
|
+
case 0:
|
|
4667
|
+
bits = 0;
|
|
4668
|
+
maxpower = Math.pow(2,8);
|
|
4669
|
+
power=1;
|
|
4670
|
+
while (power!=maxpower) {
|
|
4671
|
+
resb = data.val & data.position;
|
|
4672
|
+
data.position >>= 1;
|
|
4673
|
+
if (data.position == 0) {
|
|
4674
|
+
data.position = resetValue;
|
|
4675
|
+
data.val = getNextValue(data.index++);
|
|
4676
|
+
}
|
|
4677
|
+
bits |= (resb>0 ? 1 : 0) * power;
|
|
4678
|
+
power <<= 1;
|
|
4679
|
+
}
|
|
4680
|
+
c = f(bits);
|
|
4681
|
+
break;
|
|
4682
|
+
case 1:
|
|
4683
|
+
bits = 0;
|
|
4684
|
+
maxpower = Math.pow(2,16);
|
|
4685
|
+
power=1;
|
|
4686
|
+
while (power!=maxpower) {
|
|
4687
|
+
resb = data.val & data.position;
|
|
4688
|
+
data.position >>= 1;
|
|
4689
|
+
if (data.position == 0) {
|
|
4690
|
+
data.position = resetValue;
|
|
4691
|
+
data.val = getNextValue(data.index++);
|
|
4692
|
+
}
|
|
4693
|
+
bits |= (resb>0 ? 1 : 0) * power;
|
|
4694
|
+
power <<= 1;
|
|
4695
|
+
}
|
|
4696
|
+
c = f(bits);
|
|
4697
|
+
break;
|
|
4698
|
+
case 2:
|
|
4699
|
+
return "";
|
|
4700
|
+
}
|
|
4701
|
+
dictionary[3] = c;
|
|
4702
|
+
w = c;
|
|
4703
|
+
result.push(c);
|
|
4704
|
+
while (true) {
|
|
4705
|
+
if (data.index > length) {
|
|
4706
|
+
return "";
|
|
4707
|
+
}
|
|
4708
|
+
|
|
4709
|
+
bits = 0;
|
|
4710
|
+
maxpower = Math.pow(2,numBits);
|
|
4711
|
+
power=1;
|
|
4712
|
+
while (power!=maxpower) {
|
|
4713
|
+
resb = data.val & data.position;
|
|
4714
|
+
data.position >>= 1;
|
|
4715
|
+
if (data.position == 0) {
|
|
4716
|
+
data.position = resetValue;
|
|
4717
|
+
data.val = getNextValue(data.index++);
|
|
4718
|
+
}
|
|
4719
|
+
bits |= (resb>0 ? 1 : 0) * power;
|
|
4720
|
+
power <<= 1;
|
|
4721
|
+
}
|
|
4722
|
+
|
|
4723
|
+
switch (c = bits) {
|
|
4724
|
+
case 0:
|
|
4725
|
+
bits = 0;
|
|
4726
|
+
maxpower = Math.pow(2,8);
|
|
4727
|
+
power=1;
|
|
4728
|
+
while (power!=maxpower) {
|
|
4729
|
+
resb = data.val & data.position;
|
|
4730
|
+
data.position >>= 1;
|
|
4731
|
+
if (data.position == 0) {
|
|
4732
|
+
data.position = resetValue;
|
|
4733
|
+
data.val = getNextValue(data.index++);
|
|
4734
|
+
}
|
|
4735
|
+
bits |= (resb>0 ? 1 : 0) * power;
|
|
4736
|
+
power <<= 1;
|
|
4737
|
+
}
|
|
4738
|
+
|
|
4739
|
+
dictionary[dictSize++] = f(bits);
|
|
4740
|
+
c = dictSize-1;
|
|
4741
|
+
enlargeIn--;
|
|
4742
|
+
break;
|
|
4743
|
+
case 1:
|
|
4744
|
+
bits = 0;
|
|
4745
|
+
maxpower = Math.pow(2,16);
|
|
4746
|
+
power=1;
|
|
4747
|
+
while (power!=maxpower) {
|
|
4748
|
+
resb = data.val & data.position;
|
|
4749
|
+
data.position >>= 1;
|
|
4750
|
+
if (data.position == 0) {
|
|
4751
|
+
data.position = resetValue;
|
|
4752
|
+
data.val = getNextValue(data.index++);
|
|
4753
|
+
}
|
|
4754
|
+
bits |= (resb>0 ? 1 : 0) * power;
|
|
4755
|
+
power <<= 1;
|
|
4756
|
+
}
|
|
4757
|
+
dictionary[dictSize++] = f(bits);
|
|
4758
|
+
c = dictSize-1;
|
|
4759
|
+
enlargeIn--;
|
|
4760
|
+
break;
|
|
4761
|
+
case 2:
|
|
4762
|
+
return result.join('');
|
|
4763
|
+
}
|
|
4764
|
+
|
|
4765
|
+
if (enlargeIn == 0) {
|
|
4766
|
+
enlargeIn = Math.pow(2, numBits);
|
|
4767
|
+
numBits++;
|
|
4768
|
+
}
|
|
4769
|
+
|
|
4770
|
+
if (dictionary[c]) {
|
|
4771
|
+
entry = dictionary[c];
|
|
4772
|
+
} else {
|
|
4773
|
+
if (c === dictSize) {
|
|
4774
|
+
entry = w + w.charAt(0);
|
|
4775
|
+
} else {
|
|
4776
|
+
return null;
|
|
4777
|
+
}
|
|
4778
|
+
}
|
|
4779
|
+
result.push(entry);
|
|
4780
|
+
|
|
4781
|
+
// Add w+entry[0] to the dictionary.
|
|
4782
|
+
dictionary[dictSize++] = w + entry.charAt(0);
|
|
4783
|
+
enlargeIn--;
|
|
4784
|
+
|
|
4785
|
+
w = entry;
|
|
4786
|
+
|
|
4787
|
+
if (enlargeIn == 0) {
|
|
4788
|
+
enlargeIn = Math.pow(2, numBits);
|
|
4789
|
+
numBits++;
|
|
4790
|
+
}
|
|
4791
|
+
|
|
4792
|
+
}
|
|
4793
|
+
}
|
|
4794
|
+
};
|
|
4795
|
+
return LZString;
|
|
4796
|
+
})();
|
|
4797
|
+
|
|
4798
|
+
if (true) {
|
|
4799
|
+
!(__WEBPACK_AMD_DEFINE_RESULT__ = (function () { return LZString; }).call(exports, __webpack_require__, exports, module),
|
|
4800
|
+
__WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
|
|
4801
|
+
} else {}
|
|
4802
|
+
|
|
4803
|
+
|
|
4804
|
+
/***/ }),
|
|
4805
|
+
|
|
4806
|
+
/***/ "./src/Base64.js":
|
|
4807
|
+
/*!***********************!*\
|
|
4808
|
+
!*** ./src/Base64.js ***!
|
|
4809
|
+
\***********************/
|
|
4810
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
4811
|
+
|
|
4812
|
+
"use strict";
|
|
4813
|
+
__webpack_require__.r(__webpack_exports__);
|
|
4814
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
4815
|
+
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
|
|
4816
|
+
/* harmony export */ });
|
|
4817
|
+
const Base64 = {
|
|
4818
|
+
_keyStr: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=',
|
|
4819
|
+
encode: function (e) {
|
|
4820
|
+
let t = '';
|
|
4821
|
+
let n, r, i, s, o, u, a;
|
|
4822
|
+
let f = 0;
|
|
4823
|
+
e = Base64._utf8Encode(e);
|
|
4824
|
+
while (f < e.length) {
|
|
4825
|
+
n = e.charCodeAt(f++);
|
|
4826
|
+
r = e.charCodeAt(f++);
|
|
4827
|
+
i = e.charCodeAt(f++);
|
|
4828
|
+
s = n >> 2;
|
|
4829
|
+
o = (n & 3) << 4 | r >> 4;
|
|
4830
|
+
u = (r & 15) << 2 | i >> 6;
|
|
4831
|
+
a = i & 63;
|
|
4832
|
+
if (isNaN(r)) {
|
|
4833
|
+
u = a = 64;
|
|
4834
|
+
} else if (isNaN(i)) {
|
|
4835
|
+
a = 64;
|
|
4836
|
+
}
|
|
4837
|
+
t = t + this._keyStr.charAt(s) + this._keyStr.charAt(o) + this._keyStr.charAt(u) + this._keyStr.charAt(a);
|
|
4838
|
+
}
|
|
4839
|
+
return t;
|
|
4840
|
+
},
|
|
4841
|
+
decode: function (e) {
|
|
4842
|
+
let t = '';
|
|
4843
|
+
let n, r, i;
|
|
4844
|
+
let s, o, u, a;
|
|
4845
|
+
let f = 0;
|
|
4846
|
+
e = e.replace(/[^A-Za-z0-9+/=]/g, '');
|
|
4847
|
+
while (f < e.length) {
|
|
4848
|
+
s = this._keyStr.indexOf(e.charAt(f++));
|
|
4849
|
+
o = this._keyStr.indexOf(e.charAt(f++));
|
|
4850
|
+
u = this._keyStr.indexOf(e.charAt(f++));
|
|
4851
|
+
a = this._keyStr.indexOf(e.charAt(f++));
|
|
4852
|
+
n = s << 2 | o >> 4;
|
|
4853
|
+
r = (o & 15) << 4 | u >> 2;
|
|
4854
|
+
i = (u & 3) << 6 | a;
|
|
4855
|
+
t = t + String.fromCharCode(n);
|
|
4856
|
+
if (u !== 64) {
|
|
4857
|
+
t = t + String.fromCharCode(r);
|
|
4858
|
+
}
|
|
4859
|
+
if (a !== 64) {
|
|
4860
|
+
t = t + String.fromCharCode(i);
|
|
4861
|
+
}
|
|
4862
|
+
}
|
|
4863
|
+
t = Base64._utf8Decode(t);
|
|
4864
|
+
return t;
|
|
4865
|
+
},
|
|
4866
|
+
_utf8Encode: function (e) {
|
|
4867
|
+
e = e.replace(/\r\n/g, '\n');
|
|
4868
|
+
let t = '';
|
|
4869
|
+
for (let n = 0; n < e.length; n++) {
|
|
4870
|
+
let r = e.charCodeAt(n);
|
|
4871
|
+
if (r < 128) {
|
|
4872
|
+
t += String.fromCharCode(r);
|
|
4873
|
+
} else if (r > 127 && r < 2048) {
|
|
4874
|
+
t += String.fromCharCode(r >> 6 | 192);
|
|
4875
|
+
t += String.fromCharCode(r & 63 | 128);
|
|
4876
|
+
} else {
|
|
4877
|
+
t += String.fromCharCode(r >> 12 | 224);
|
|
4878
|
+
t += String.fromCharCode(r >> 6 & 63 | 128);
|
|
4879
|
+
t += String.fromCharCode(r & 63 | 128);
|
|
4880
|
+
}
|
|
4881
|
+
}
|
|
4882
|
+
return t;
|
|
4883
|
+
},
|
|
4884
|
+
_utf8Decode: function (e) {
|
|
4885
|
+
let t = '';
|
|
4886
|
+
let n = 0;
|
|
4887
|
+
let r, c2, c3;
|
|
4888
|
+
r = c2 = 0;
|
|
4889
|
+
while (n < e.length) {
|
|
4890
|
+
r = e.charCodeAt(n);
|
|
4891
|
+
if (r < 128) {
|
|
4892
|
+
t += String.fromCharCode(r);
|
|
4893
|
+
n++;
|
|
4894
|
+
} else if (r > 191 && r < 224) {
|
|
4895
|
+
c2 = e.charCodeAt(n + 1);
|
|
4896
|
+
t += String.fromCharCode((r & 31) << 6 | c2 & 63);
|
|
4897
|
+
n += 2;
|
|
4898
|
+
} else {
|
|
4899
|
+
c2 = e.charCodeAt(n + 1);
|
|
4900
|
+
c3 = e.charCodeAt(n + 2);
|
|
4901
|
+
t += String.fromCharCode((r & 15) << 12 | (c2 & 63) << 6 | c3 & 63);
|
|
4902
|
+
n += 3;
|
|
4903
|
+
}
|
|
4904
|
+
}
|
|
4905
|
+
return t;
|
|
4906
|
+
}
|
|
4907
|
+
};
|
|
4908
|
+
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (Base64);
|
|
4909
|
+
|
|
4910
|
+
/***/ }),
|
|
4911
|
+
|
|
4912
|
+
/***/ "./src/SecureLS.js":
|
|
4913
|
+
/*!*************************!*\
|
|
4914
|
+
!*** ./src/SecureLS.js ***!
|
|
4915
|
+
\*************************/
|
|
4916
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
4917
|
+
|
|
4918
|
+
"use strict";
|
|
4919
|
+
__webpack_require__.r(__webpack_exports__);
|
|
4920
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
4921
|
+
/* harmony export */ SecureLS: () => (/* binding */ SecureLS)
|
|
4922
|
+
/* harmony export */ });
|
|
4923
|
+
/* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./constants */ "./src/constants.js");
|
|
4924
|
+
/* harmony import */ var _enc_utf8__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./enc-utf8 */ "./src/enc-utf8.js");
|
|
4925
|
+
/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./utils */ "./src/utils.js");
|
|
4926
|
+
/* harmony import */ var crypto_js_aes__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! crypto-js/aes */ "./node_modules/crypto-js/aes.js");
|
|
4927
|
+
/* harmony import */ var crypto_js_aes__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(crypto_js_aes__WEBPACK_IMPORTED_MODULE_3__);
|
|
4928
|
+
/* harmony import */ var crypto_js_rabbit__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! crypto-js/rabbit */ "./node_modules/crypto-js/rabbit.js");
|
|
4929
|
+
/* harmony import */ var crypto_js_rabbit__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(crypto_js_rabbit__WEBPACK_IMPORTED_MODULE_4__);
|
|
4930
|
+
/* harmony import */ var crypto_js_rc4__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! crypto-js/rc4 */ "./node_modules/crypto-js/rc4.js");
|
|
4931
|
+
/* harmony import */ var crypto_js_rc4__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(crypto_js_rc4__WEBPACK_IMPORTED_MODULE_5__);
|
|
4932
|
+
/* harmony import */ var crypto_js_tripledes__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! crypto-js/tripledes */ "./node_modules/crypto-js/tripledes.js");
|
|
4933
|
+
/* harmony import */ var crypto_js_tripledes__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(crypto_js_tripledes__WEBPACK_IMPORTED_MODULE_6__);
|
|
4934
|
+
/* harmony import */ var lz_string_libs_lz_string__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! lz-string/libs/lz-string */ "./node_modules/lz-string/libs/lz-string.js");
|
|
4935
|
+
/* harmony import */ var lz_string_libs_lz_string__WEBPACK_IMPORTED_MODULE_7___default = /*#__PURE__*/__webpack_require__.n(lz_string_libs_lz_string__WEBPACK_IMPORTED_MODULE_7__);
|
|
4936
|
+
/* harmony import */ var _Base64__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./Base64 */ "./src/Base64.js");
|
|
4937
|
+
|
|
4938
|
+
|
|
4939
|
+
|
|
4940
|
+
|
|
4941
|
+
|
|
4942
|
+
|
|
4943
|
+
|
|
4944
|
+
|
|
4945
|
+
|
|
4946
|
+
const encryptors = {
|
|
4947
|
+
[_constants__WEBPACK_IMPORTED_MODULE_0__["default"].EncrytionTypes.AES]: (crypto_js_aes__WEBPACK_IMPORTED_MODULE_3___default()),
|
|
4948
|
+
[_constants__WEBPACK_IMPORTED_MODULE_0__["default"].EncrytionTypes.DES]: (crypto_js_tripledes__WEBPACK_IMPORTED_MODULE_6___default()),
|
|
4949
|
+
[_constants__WEBPACK_IMPORTED_MODULE_0__["default"].EncrytionTypes.RABBIT]: (crypto_js_rabbit__WEBPACK_IMPORTED_MODULE_4___default()),
|
|
4950
|
+
[_constants__WEBPACK_IMPORTED_MODULE_0__["default"].EncrytionTypes.RC4]: (crypto_js_rc4__WEBPACK_IMPORTED_MODULE_5___default())
|
|
4951
|
+
};
|
|
4952
|
+
class SecureLS {
|
|
4953
|
+
constructor({
|
|
4954
|
+
encryptionSecret = '',
|
|
4955
|
+
encryptionNamespace = '',
|
|
4956
|
+
isCompression = true,
|
|
4957
|
+
encodingType = _constants__WEBPACK_IMPORTED_MODULE_0__["default"].EncrytionTypes.BASE64,
|
|
4958
|
+
storage = localStorage,
|
|
4959
|
+
metaKey = _constants__WEBPACK_IMPORTED_MODULE_0__["default"].metaKey
|
|
4960
|
+
} = {}) {
|
|
4961
|
+
// Assign libraries and utilities
|
|
4962
|
+
Object.assign(this, {
|
|
4963
|
+
_name: 'secure-ls',
|
|
4964
|
+
Base64: _Base64__WEBPACK_IMPORTED_MODULE_8__["default"],
|
|
4965
|
+
LZString: {
|
|
4966
|
+
compressToUTF16: lz_string_libs_lz_string__WEBPACK_IMPORTED_MODULE_7__.compressToUTF16,
|
|
4967
|
+
decompressFromUTF16: lz_string_libs_lz_string__WEBPACK_IMPORTED_MODULE_7__.decompressFromUTF16
|
|
4968
|
+
},
|
|
4969
|
+
AES: (crypto_js_aes__WEBPACK_IMPORTED_MODULE_3___default()),
|
|
4970
|
+
DES: (crypto_js_tripledes__WEBPACK_IMPORTED_MODULE_6___default()),
|
|
4971
|
+
RABBIT: (crypto_js_rabbit__WEBPACK_IMPORTED_MODULE_4___default()),
|
|
4972
|
+
RC4: (crypto_js_rc4__WEBPACK_IMPORTED_MODULE_5___default()),
|
|
4973
|
+
enc: _enc_utf8__WEBPACK_IMPORTED_MODULE_1__["default"]
|
|
4974
|
+
});
|
|
4975
|
+
|
|
4976
|
+
// Configuration and property assignment
|
|
4977
|
+
this.config = {
|
|
4978
|
+
encryptionSecret,
|
|
4979
|
+
encryptionNamespace,
|
|
4980
|
+
isCompression,
|
|
4981
|
+
encodingType: encodingType.toLowerCase(),
|
|
4982
|
+
storage,
|
|
4983
|
+
metaKey
|
|
4984
|
+
};
|
|
4985
|
+
this.encryptionSecret = encryptionSecret;
|
|
4986
|
+
this.storage = storage;
|
|
4987
|
+
this.metaKey = metaKey;
|
|
4988
|
+
|
|
4989
|
+
// Initialize the class
|
|
4990
|
+
this.init();
|
|
4991
|
+
}
|
|
4992
|
+
init() {
|
|
4993
|
+
let metaData = this.getMetaData();
|
|
4994
|
+
this._isBase64 = this._isBase64EncryptionType();
|
|
4995
|
+
this._isAES = this._isAESEncryptionType();
|
|
4996
|
+
this._isDES = this._isDESEncryptionType();
|
|
4997
|
+
this._isRabbit = this._isRabbitEncryptionType();
|
|
4998
|
+
this._isRC4 = this._isRC4EncryptionType();
|
|
4999
|
+
this._isCompression = this._isDataCompressionEnabled();
|
|
5000
|
+
|
|
5001
|
+
// fill the already present keys to the list of keys being used by secure-ls
|
|
5002
|
+
this.allKeys = metaData.keys || this.resetAllKeys();
|
|
5003
|
+
}
|
|
5004
|
+
_isBase64EncryptionType() {
|
|
5005
|
+
return _Base64__WEBPACK_IMPORTED_MODULE_8__["default"] && (typeof this.config.encodingType === 'undefined' || this.config.encodingType === _constants__WEBPACK_IMPORTED_MODULE_0__["default"].EncrytionTypes.BASE64);
|
|
5006
|
+
}
|
|
5007
|
+
_isAESEncryptionType() {
|
|
5008
|
+
return (crypto_js_aes__WEBPACK_IMPORTED_MODULE_3___default()) && this.config.encodingType === _constants__WEBPACK_IMPORTED_MODULE_0__["default"].EncrytionTypes.AES;
|
|
5009
|
+
}
|
|
5010
|
+
_isDESEncryptionType() {
|
|
5011
|
+
return (crypto_js_tripledes__WEBPACK_IMPORTED_MODULE_6___default()) && this.config.encodingType === _constants__WEBPACK_IMPORTED_MODULE_0__["default"].EncrytionTypes.DES;
|
|
5012
|
+
}
|
|
5013
|
+
_isRabbitEncryptionType() {
|
|
5014
|
+
return (crypto_js_rabbit__WEBPACK_IMPORTED_MODULE_4___default()) && this.config.encodingType === _constants__WEBPACK_IMPORTED_MODULE_0__["default"].EncrytionTypes.RABBIT;
|
|
5015
|
+
}
|
|
5016
|
+
_isRC4EncryptionType() {
|
|
5017
|
+
return (crypto_js_rc4__WEBPACK_IMPORTED_MODULE_5___default()) && this.config.encodingType === _constants__WEBPACK_IMPORTED_MODULE_0__["default"].EncrytionTypes.RC4;
|
|
5018
|
+
}
|
|
5019
|
+
_isDataCompressionEnabled() {
|
|
5020
|
+
return this.config.isCompression;
|
|
5021
|
+
}
|
|
5022
|
+
getEncryptionSecret(key) {
|
|
5023
|
+
let metaData = this.getMetaData();
|
|
5024
|
+
let obj = _utils__WEBPACK_IMPORTED_MODULE_2__["default"].getObjectFromKey(metaData.keys, key);
|
|
5025
|
+
if (!obj) {
|
|
5026
|
+
return;
|
|
5027
|
+
}
|
|
5028
|
+
if (this._isAES || this._isDES || this._isRabbit || this._isRC4) {
|
|
5029
|
+
if (typeof this.config.encryptionSecret === 'undefined') {
|
|
5030
|
+
this.encryptionSecret = obj.s;
|
|
5031
|
+
if (!this.encryptionSecret) {
|
|
5032
|
+
this.encryptionSecret = _utils__WEBPACK_IMPORTED_MODULE_2__["default"].generateSecretKey();
|
|
5033
|
+
this.setMetaData();
|
|
5034
|
+
}
|
|
5035
|
+
} else {
|
|
5036
|
+
this.encryptionSecret = this.config.encryptionSecret || obj.s || '';
|
|
5037
|
+
}
|
|
5038
|
+
}
|
|
5039
|
+
}
|
|
5040
|
+
getEncryptionType() {
|
|
5041
|
+
const encodingType = this.config.encodingType;
|
|
5042
|
+
return encodingType ? encodingType.toLowerCase() : _constants__WEBPACK_IMPORTED_MODULE_0__["default"].EncrytionTypes.BASE64;
|
|
5043
|
+
}
|
|
5044
|
+
getDataFromLocalStorage(key) {
|
|
5045
|
+
return this.storage.getItem(key, true);
|
|
5046
|
+
}
|
|
5047
|
+
setDataToLocalStorage(key, data) {
|
|
5048
|
+
this.storage.setItem(key, data);
|
|
5049
|
+
}
|
|
5050
|
+
setMetaData() {
|
|
5051
|
+
let dataToStore = this.processData({
|
|
5052
|
+
keys: this.allKeys
|
|
5053
|
+
}, true);
|
|
5054
|
+
|
|
5055
|
+
// Store the data to localStorage
|
|
5056
|
+
this.setDataToLocalStorage(this.getMetaKey(), dataToStore);
|
|
5057
|
+
}
|
|
5058
|
+
getMetaData() {
|
|
5059
|
+
return this.get(this.getMetaKey(), true) || {};
|
|
5060
|
+
}
|
|
5061
|
+
getMetaKey() {
|
|
5062
|
+
return this.metaKey + (this.config.encryptionNamespace ? '__' + this.config.encryptionNamespace : '');
|
|
5063
|
+
}
|
|
5064
|
+
resetAllKeys() {
|
|
5065
|
+
this.allKeys = [];
|
|
5066
|
+
return [];
|
|
5067
|
+
}
|
|
5068
|
+
processData(data, isAllKeysData) {
|
|
5069
|
+
if (data === null || data === undefined || data === '') {
|
|
5070
|
+
return '';
|
|
5071
|
+
}
|
|
5072
|
+
let jsonData;
|
|
5073
|
+
try {
|
|
5074
|
+
jsonData = JSON.stringify(data);
|
|
5075
|
+
} catch (err) {
|
|
5076
|
+
throw new Error('Could not stringify data', err);
|
|
5077
|
+
}
|
|
5078
|
+
|
|
5079
|
+
// Encode Based on encoding type
|
|
5080
|
+
// If not set, default to Base64 for securing data
|
|
5081
|
+
let encodedData = jsonData;
|
|
5082
|
+
if (this._isBase64 || isAllKeysData) {
|
|
5083
|
+
encodedData = _Base64__WEBPACK_IMPORTED_MODULE_8__["default"].encode(jsonData);
|
|
5084
|
+
} else {
|
|
5085
|
+
const encryptor = encryptors[this.getEncryptionType()];
|
|
5086
|
+
if (encryptor) {
|
|
5087
|
+
encodedData = encryptor.encrypt(jsonData, this.encryptionSecret);
|
|
5088
|
+
}
|
|
5089
|
+
encodedData = encodedData && encodedData.toString();
|
|
5183
5090
|
}
|
|
5184
5091
|
|
|
5185
|
-
//
|
|
5186
|
-
|
|
5187
|
-
|
|
5188
|
-
|
|
5189
|
-
|
|
5190
|
-
|
|
5191
|
-
|
|
5192
|
-
|
|
5193
|
-
|
|
5194
|
-
|
|
5092
|
+
// Compress data if set to true
|
|
5093
|
+
let compressedData = encodedData;
|
|
5094
|
+
if (this._isCompression || isAllKeysData) {
|
|
5095
|
+
compressedData = this.LZString.compressToUTF16(encodedData);
|
|
5096
|
+
}
|
|
5097
|
+
return compressedData;
|
|
5098
|
+
}
|
|
5099
|
+
|
|
5100
|
+
// PUBLIC APIs
|
|
5101
|
+
getAllKeys() {
|
|
5102
|
+
let data = this.getMetaData();
|
|
5103
|
+
return _utils__WEBPACK_IMPORTED_MODULE_2__["default"].extractKeyNames(data) || [];
|
|
5104
|
+
}
|
|
5105
|
+
get(key, isAllKeysData) {
|
|
5106
|
+
let decodedData = '';
|
|
5107
|
+
let jsonData = '';
|
|
5108
|
+
if (!_utils__WEBPACK_IMPORTED_MODULE_2__["default"].is(key)) {
|
|
5109
|
+
_utils__WEBPACK_IMPORTED_MODULE_2__["default"].warn(_constants__WEBPACK_IMPORTED_MODULE_0__["default"].WarningEnum.KEY_NOT_PROVIDED);
|
|
5110
|
+
return jsonData;
|
|
5111
|
+
}
|
|
5112
|
+
let data = this.getDataFromLocalStorage(key);
|
|
5113
|
+
if (!data) {
|
|
5114
|
+
return jsonData;
|
|
5115
|
+
}
|
|
5116
|
+
let deCompressedData = data; // saves else
|
|
5117
|
+
if (this._isCompression || isAllKeysData) {
|
|
5118
|
+
// meta data always compressed
|
|
5119
|
+
deCompressedData = this.LZString.decompressFromUTF16(data);
|
|
5120
|
+
}
|
|
5121
|
+
decodedData = deCompressedData; // saves else
|
|
5122
|
+
if (this._isBase64 || isAllKeysData) {
|
|
5123
|
+
// meta data always Base64
|
|
5124
|
+
decodedData = _Base64__WEBPACK_IMPORTED_MODULE_8__["default"].decode(deCompressedData);
|
|
5125
|
+
} else {
|
|
5126
|
+
this.getEncryptionSecret(key);
|
|
5127
|
+
const encryptor = encryptors[this.getEncryptionType()];
|
|
5128
|
+
if (encryptor) {
|
|
5129
|
+
const bytes = encryptor.decrypt(deCompressedData.toString(), this.encryptionSecret);
|
|
5130
|
+
if (bytes) {
|
|
5131
|
+
decodedData = bytes.toString(_enc_utf8__WEBPACK_IMPORTED_MODULE_1__["default"]._Utf8);
|
|
5132
|
+
}
|
|
5195
5133
|
}
|
|
5196
|
-
value = value >> 1;
|
|
5197
5134
|
}
|
|
5135
|
+
try {
|
|
5136
|
+
jsonData = JSON.parse(decodedData);
|
|
5137
|
+
} catch (err) {
|
|
5138
|
+
throw new Error('Could not parse JSON', err);
|
|
5139
|
+
}
|
|
5140
|
+
return jsonData;
|
|
5141
|
+
}
|
|
5142
|
+
set(key, data) {
|
|
5143
|
+
let dataToStore = '';
|
|
5144
|
+
if (!_utils__WEBPACK_IMPORTED_MODULE_2__["default"].is(key)) {
|
|
5145
|
+
_utils__WEBPACK_IMPORTED_MODULE_2__["default"].warn(_constants__WEBPACK_IMPORTED_MODULE_0__["default"].WarningEnum.KEY_NOT_PROVIDED);
|
|
5146
|
+
return;
|
|
5147
|
+
}
|
|
5148
|
+
this.getEncryptionSecret(key);
|
|
5198
5149
|
|
|
5199
|
-
//
|
|
5200
|
-
|
|
5201
|
-
|
|
5202
|
-
|
|
5203
|
-
|
|
5204
|
-
|
|
5150
|
+
// add key(s) to Array if not already added, only for keys other than meta key
|
|
5151
|
+
if (!(String(key) === String(this.metaKey))) {
|
|
5152
|
+
if (!_utils__WEBPACK_IMPORTED_MODULE_2__["default"].isKeyPresent(this.allKeys, key)) {
|
|
5153
|
+
this.allKeys.push({
|
|
5154
|
+
k: key,
|
|
5155
|
+
s: this.encryptionSecret
|
|
5156
|
+
});
|
|
5157
|
+
this.setMetaData();
|
|
5205
5158
|
}
|
|
5206
|
-
else context_data_position++;
|
|
5207
5159
|
}
|
|
5208
|
-
|
|
5160
|
+
dataToStore = this.processData(data);
|
|
5161
|
+
// Store the data to localStorage
|
|
5162
|
+
this.setDataToLocalStorage(key, dataToStore);
|
|
5163
|
+
}
|
|
5164
|
+
remove(key) {
|
|
5165
|
+
if (!_utils__WEBPACK_IMPORTED_MODULE_2__["default"].is(key)) {
|
|
5166
|
+
_utils__WEBPACK_IMPORTED_MODULE_2__["default"].warn(_constants__WEBPACK_IMPORTED_MODULE_0__["default"].WarningEnum.KEY_NOT_PROVIDED);
|
|
5167
|
+
return;
|
|
5168
|
+
}
|
|
5169
|
+
if (key === this.metaKey && this.getAllKeys().length) {
|
|
5170
|
+
_utils__WEBPACK_IMPORTED_MODULE_2__["default"].warn(_constants__WEBPACK_IMPORTED_MODULE_0__["default"].WarningEnum.META_KEY_REMOVE);
|
|
5171
|
+
return;
|
|
5172
|
+
}
|
|
5173
|
+
if (_utils__WEBPACK_IMPORTED_MODULE_2__["default"].isKeyPresent(this.allKeys, key)) {
|
|
5174
|
+
_utils__WEBPACK_IMPORTED_MODULE_2__["default"].removeFromKeysList(this.allKeys, key);
|
|
5175
|
+
this.setMetaData();
|
|
5176
|
+
}
|
|
5177
|
+
this.storage.removeItem(key);
|
|
5178
|
+
}
|
|
5179
|
+
removeAll() {
|
|
5180
|
+
let keys = this.getAllKeys();
|
|
5181
|
+
for (let i = 0; i < keys.length; i++) {
|
|
5182
|
+
this.storage.removeItem(keys[i]);
|
|
5183
|
+
}
|
|
5184
|
+
this.storage.removeItem(this.metaKey);
|
|
5185
|
+
this.resetAllKeys();
|
|
5186
|
+
}
|
|
5187
|
+
clear() {
|
|
5188
|
+
this.storage.clear();
|
|
5189
|
+
this.resetAllKeys();
|
|
5190
|
+
}
|
|
5191
|
+
}
|
|
5192
|
+
|
|
5193
|
+
/***/ }),
|
|
5194
|
+
|
|
5195
|
+
/***/ "./src/WordArray.js":
|
|
5196
|
+
/*!**************************!*\
|
|
5197
|
+
!*** ./src/WordArray.js ***!
|
|
5198
|
+
\**************************/
|
|
5199
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
5200
|
+
|
|
5201
|
+
"use strict";
|
|
5202
|
+
__webpack_require__.r(__webpack_exports__);
|
|
5203
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
5204
|
+
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
|
|
5205
|
+
/* harmony export */ });
|
|
5206
|
+
/*
|
|
5207
|
+
ES6 compatible port of CryptoJS - WordArray for PBKDF2 password key generation
|
|
5208
|
+
|
|
5209
|
+
Source: https://github.com/brix/crypto-js
|
|
5210
|
+
LICENSE: MIT
|
|
5211
|
+
*/
|
|
5212
|
+
|
|
5213
|
+
let CryptoJSWordArray = {
|
|
5214
|
+
random: function (nBytes) {
|
|
5215
|
+
let words = [];
|
|
5216
|
+
let r = function (mw) {
|
|
5217
|
+
let mz = 0x3ade68b1;
|
|
5218
|
+
let mask = 0xffffffff;
|
|
5219
|
+
return function () {
|
|
5220
|
+
mz = 0x9069 * (mz & 0xffff) + (mz >> 0x10) & mask;
|
|
5221
|
+
mw = 0x4650 * (mw & 0xffff) + (mw >> 0x10) & mask;
|
|
5222
|
+
let result = (mz << 0x10) + mw & mask;
|
|
5223
|
+
result /= 0x100000000;
|
|
5224
|
+
result += 0.5;
|
|
5225
|
+
return result * (Math.random() > 0.5 ? 1 : -1);
|
|
5226
|
+
};
|
|
5227
|
+
};
|
|
5228
|
+
for (let i = 0, rcache; i < nBytes; i += 4) {
|
|
5229
|
+
let _r = r((rcache || Math.random()) * 0x100000000);
|
|
5230
|
+
rcache = _r() * 0x3ade67b7;
|
|
5231
|
+
words.push(_r() * 0x100000000 | 0);
|
|
5232
|
+
}
|
|
5233
|
+
return new CryptoJSWordArray.Set(words, nBytes);
|
|
5209
5234
|
},
|
|
5235
|
+
Set: function (words, sigBytes) {
|
|
5236
|
+
words = this.words = words || [];
|
|
5237
|
+
if (sigBytes !== undefined) {
|
|
5238
|
+
this.sigBytes = sigBytes;
|
|
5239
|
+
} else {
|
|
5240
|
+
this.sigBytes = words.length * 8;
|
|
5241
|
+
}
|
|
5242
|
+
}
|
|
5243
|
+
};
|
|
5244
|
+
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (CryptoJSWordArray);
|
|
5210
5245
|
|
|
5211
|
-
|
|
5212
|
-
|
|
5213
|
-
|
|
5214
|
-
|
|
5246
|
+
/***/ }),
|
|
5247
|
+
|
|
5248
|
+
/***/ "./src/constants.js":
|
|
5249
|
+
/*!**************************!*\
|
|
5250
|
+
!*** ./src/constants.js ***!
|
|
5251
|
+
\**************************/
|
|
5252
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
5253
|
+
|
|
5254
|
+
"use strict";
|
|
5255
|
+
__webpack_require__.r(__webpack_exports__);
|
|
5256
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
5257
|
+
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
|
|
5258
|
+
/* harmony export */ });
|
|
5259
|
+
const WarningEnum = {
|
|
5260
|
+
KEY_NOT_PROVIDED: 'keyNotProvided',
|
|
5261
|
+
META_KEY_REMOVE: 'metaKeyRemove',
|
|
5262
|
+
DEFAULT_TEXT: 'defaultText'
|
|
5263
|
+
};
|
|
5264
|
+
const WarningTypes = {};
|
|
5265
|
+
WarningTypes[WarningEnum.KEY_NOT_PROVIDED] = 'Secure LS: Key not provided. Aborting operation!';
|
|
5266
|
+
WarningTypes[WarningEnum.META_KEY_REMOVE] = `Secure LS: Meta key can not be removed
|
|
5267
|
+
unless all keys created by Secure LS are removed!`;
|
|
5268
|
+
WarningTypes[WarningEnum.DEFAULT_TEXT] = `Unexpected output`;
|
|
5269
|
+
const constants = {
|
|
5270
|
+
WarningEnum: WarningEnum,
|
|
5271
|
+
WarningTypes: WarningTypes,
|
|
5272
|
+
EncrytionTypes: {
|
|
5273
|
+
BASE64: 'base64',
|
|
5274
|
+
AES: 'aes',
|
|
5275
|
+
DES: 'des',
|
|
5276
|
+
RABBIT: 'rabbit',
|
|
5277
|
+
RC4: 'rc4'
|
|
5215
5278
|
},
|
|
5279
|
+
metaKey: '_secure__ls__metadata',
|
|
5280
|
+
secretPhrase: 's3cr3t$#@135^&*246'
|
|
5281
|
+
};
|
|
5282
|
+
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (constants);
|
|
5216
5283
|
|
|
5217
|
-
|
|
5218
|
-
var dictionary = [],
|
|
5219
|
-
next,
|
|
5220
|
-
enlargeIn = 4,
|
|
5221
|
-
dictSize = 4,
|
|
5222
|
-
numBits = 3,
|
|
5223
|
-
entry = "",
|
|
5224
|
-
result = [],
|
|
5225
|
-
i,
|
|
5226
|
-
w,
|
|
5227
|
-
bits, resb, maxpower, power,
|
|
5228
|
-
c,
|
|
5229
|
-
data = {val:getNextValue(0), position:resetValue, index:1};
|
|
5284
|
+
/***/ }),
|
|
5230
5285
|
|
|
5231
|
-
|
|
5232
|
-
|
|
5233
|
-
|
|
5286
|
+
/***/ "./src/enc-utf8.js":
|
|
5287
|
+
/*!*************************!*\
|
|
5288
|
+
!*** ./src/enc-utf8.js ***!
|
|
5289
|
+
\*************************/
|
|
5290
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
5234
5291
|
|
|
5235
|
-
|
|
5236
|
-
|
|
5237
|
-
|
|
5238
|
-
|
|
5239
|
-
|
|
5240
|
-
|
|
5241
|
-
|
|
5242
|
-
data.position = resetValue;
|
|
5243
|
-
data.val = getNextValue(data.index++);
|
|
5244
|
-
}
|
|
5245
|
-
bits |= (resb>0 ? 1 : 0) * power;
|
|
5246
|
-
power <<= 1;
|
|
5247
|
-
}
|
|
5292
|
+
"use strict";
|
|
5293
|
+
__webpack_require__.r(__webpack_exports__);
|
|
5294
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
5295
|
+
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
|
|
5296
|
+
/* harmony export */ });
|
|
5297
|
+
/*
|
|
5298
|
+
ES6 compatible port of CryptoJS - encoding
|
|
5248
5299
|
|
|
5249
|
-
|
|
5250
|
-
|
|
5251
|
-
|
|
5252
|
-
|
|
5253
|
-
|
|
5254
|
-
|
|
5255
|
-
|
|
5256
|
-
|
|
5257
|
-
|
|
5258
|
-
|
|
5259
|
-
|
|
5260
|
-
|
|
5261
|
-
bits |= (resb>0 ? 1 : 0) * power;
|
|
5262
|
-
power <<= 1;
|
|
5263
|
-
}
|
|
5264
|
-
c = f(bits);
|
|
5265
|
-
break;
|
|
5266
|
-
case 1:
|
|
5267
|
-
bits = 0;
|
|
5268
|
-
maxpower = Math.pow(2,16);
|
|
5269
|
-
power=1;
|
|
5270
|
-
while (power!=maxpower) {
|
|
5271
|
-
resb = data.val & data.position;
|
|
5272
|
-
data.position >>= 1;
|
|
5273
|
-
if (data.position == 0) {
|
|
5274
|
-
data.position = resetValue;
|
|
5275
|
-
data.val = getNextValue(data.index++);
|
|
5276
|
-
}
|
|
5277
|
-
bits |= (resb>0 ? 1 : 0) * power;
|
|
5278
|
-
power <<= 1;
|
|
5279
|
-
}
|
|
5280
|
-
c = f(bits);
|
|
5281
|
-
break;
|
|
5282
|
-
case 2:
|
|
5283
|
-
return "";
|
|
5284
|
-
}
|
|
5285
|
-
dictionary[3] = c;
|
|
5286
|
-
w = c;
|
|
5287
|
-
result.push(c);
|
|
5288
|
-
while (true) {
|
|
5289
|
-
if (data.index > length) {
|
|
5290
|
-
return "";
|
|
5291
|
-
}
|
|
5300
|
+
Source: https://github.com/brix/crypto-js
|
|
5301
|
+
LICENSE: MIT
|
|
5302
|
+
*/
|
|
5303
|
+
const enc = {
|
|
5304
|
+
Latin1: {
|
|
5305
|
+
stringify: wordArray => {
|
|
5306
|
+
// Shortcuts
|
|
5307
|
+
let words = wordArray.words;
|
|
5308
|
+
let sigBytes = wordArray.sigBytes;
|
|
5309
|
+
let latin1Chars = [],
|
|
5310
|
+
i,
|
|
5311
|
+
bite;
|
|
5292
5312
|
|
|
5293
|
-
|
|
5294
|
-
|
|
5295
|
-
|
|
5296
|
-
|
|
5297
|
-
resb = data.val & data.position;
|
|
5298
|
-
data.position >>= 1;
|
|
5299
|
-
if (data.position == 0) {
|
|
5300
|
-
data.position = resetValue;
|
|
5301
|
-
data.val = getNextValue(data.index++);
|
|
5302
|
-
}
|
|
5303
|
-
bits |= (resb>0 ? 1 : 0) * power;
|
|
5304
|
-
power <<= 1;
|
|
5313
|
+
// Convert
|
|
5314
|
+
for (i = 0; i < sigBytes; i++) {
|
|
5315
|
+
bite = words[i >>> 2] >>> 24 - i % 4 * 8 & 0xff;
|
|
5316
|
+
latin1Chars.push(String.fromCharCode(bite));
|
|
5305
5317
|
}
|
|
5306
|
-
|
|
5307
|
-
|
|
5308
|
-
|
|
5309
|
-
|
|
5310
|
-
|
|
5311
|
-
|
|
5312
|
-
|
|
5313
|
-
|
|
5314
|
-
|
|
5315
|
-
if (data.position == 0) {
|
|
5316
|
-
data.position = resetValue;
|
|
5317
|
-
data.val = getNextValue(data.index++);
|
|
5318
|
-
}
|
|
5319
|
-
bits |= (resb>0 ? 1 : 0) * power;
|
|
5320
|
-
power <<= 1;
|
|
5321
|
-
}
|
|
5322
|
-
|
|
5323
|
-
dictionary[dictSize++] = f(bits);
|
|
5324
|
-
c = dictSize-1;
|
|
5325
|
-
enlargeIn--;
|
|
5326
|
-
break;
|
|
5327
|
-
case 1:
|
|
5328
|
-
bits = 0;
|
|
5329
|
-
maxpower = Math.pow(2,16);
|
|
5330
|
-
power=1;
|
|
5331
|
-
while (power!=maxpower) {
|
|
5332
|
-
resb = data.val & data.position;
|
|
5333
|
-
data.position >>= 1;
|
|
5334
|
-
if (data.position == 0) {
|
|
5335
|
-
data.position = resetValue;
|
|
5336
|
-
data.val = getNextValue(data.index++);
|
|
5337
|
-
}
|
|
5338
|
-
bits |= (resb>0 ? 1 : 0) * power;
|
|
5339
|
-
power <<= 1;
|
|
5340
|
-
}
|
|
5341
|
-
dictionary[dictSize++] = f(bits);
|
|
5342
|
-
c = dictSize-1;
|
|
5343
|
-
enlargeIn--;
|
|
5344
|
-
break;
|
|
5345
|
-
case 2:
|
|
5346
|
-
return result.join('');
|
|
5318
|
+
return latin1Chars.join('');
|
|
5319
|
+
}
|
|
5320
|
+
},
|
|
5321
|
+
_Utf8: {
|
|
5322
|
+
stringify: wordArray => {
|
|
5323
|
+
try {
|
|
5324
|
+
return decodeURIComponent(escape(enc.Latin1.stringify(wordArray)));
|
|
5325
|
+
} catch (err) {
|
|
5326
|
+
throw new Error('Malformed UTF-8 data', err);
|
|
5347
5327
|
}
|
|
5328
|
+
}
|
|
5329
|
+
}
|
|
5330
|
+
};
|
|
5331
|
+
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (enc);
|
|
5348
5332
|
|
|
5349
|
-
|
|
5350
|
-
enlargeIn = Math.pow(2, numBits);
|
|
5351
|
-
numBits++;
|
|
5352
|
-
}
|
|
5333
|
+
/***/ }),
|
|
5353
5334
|
|
|
5354
|
-
|
|
5355
|
-
|
|
5356
|
-
|
|
5357
|
-
|
|
5358
|
-
|
|
5359
|
-
} else {
|
|
5360
|
-
return null;
|
|
5361
|
-
}
|
|
5362
|
-
}
|
|
5363
|
-
result.push(entry);
|
|
5335
|
+
/***/ "./src/utils.js":
|
|
5336
|
+
/*!**********************!*\
|
|
5337
|
+
!*** ./src/utils.js ***!
|
|
5338
|
+
\**********************/
|
|
5339
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
5364
5340
|
|
|
5365
|
-
|
|
5366
|
-
|
|
5367
|
-
|
|
5341
|
+
"use strict";
|
|
5342
|
+
__webpack_require__.r(__webpack_exports__);
|
|
5343
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
5344
|
+
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
|
|
5345
|
+
/* harmony export */ });
|
|
5346
|
+
/* harmony import */ var crypto_js_pbkdf2__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! crypto-js/pbkdf2 */ "./node_modules/crypto-js/pbkdf2.js");
|
|
5347
|
+
/* harmony import */ var crypto_js_pbkdf2__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(crypto_js_pbkdf2__WEBPACK_IMPORTED_MODULE_0__);
|
|
5348
|
+
/* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./constants */ "./src/constants.js");
|
|
5349
|
+
/* harmony import */ var _WordArray__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./WordArray */ "./src/WordArray.js");
|
|
5368
5350
|
|
|
5369
|
-
w = entry;
|
|
5370
5351
|
|
|
5371
|
-
if (enlargeIn == 0) {
|
|
5372
|
-
enlargeIn = Math.pow(2, numBits);
|
|
5373
|
-
numBits++;
|
|
5374
|
-
}
|
|
5375
5352
|
|
|
5353
|
+
const utils = {
|
|
5354
|
+
is: key => !!key,
|
|
5355
|
+
warn: (reason = _constants__WEBPACK_IMPORTED_MODULE_1__["default"].WarningEnum.DEFAULT_TEXT) => {
|
|
5356
|
+
console.warn(_constants__WEBPACK_IMPORTED_MODULE_1__["default"].WarningTypes[reason]);
|
|
5357
|
+
},
|
|
5358
|
+
generateSecretKey: () => {
|
|
5359
|
+
const salt = _WordArray__WEBPACK_IMPORTED_MODULE_2__["default"].random(128 / 8);
|
|
5360
|
+
const key128Bits = crypto_js_pbkdf2__WEBPACK_IMPORTED_MODULE_0___default()(_constants__WEBPACK_IMPORTED_MODULE_1__["default"].secretPhrase, salt, {
|
|
5361
|
+
keySize: 128 / 32
|
|
5362
|
+
});
|
|
5363
|
+
return key128Bits.toString();
|
|
5364
|
+
},
|
|
5365
|
+
getObjectFromKey: (data = [], key) => {
|
|
5366
|
+
return data.find(item => item.k === key) || {};
|
|
5367
|
+
},
|
|
5368
|
+
extractKeyNames: ({
|
|
5369
|
+
keys = []
|
|
5370
|
+
} = {}) => {
|
|
5371
|
+
return keys.map(({
|
|
5372
|
+
k
|
|
5373
|
+
}) => k);
|
|
5374
|
+
},
|
|
5375
|
+
isKeyPresent: (allKeys = [], key) => {
|
|
5376
|
+
return allKeys.some(item => String(item.k) === String(key));
|
|
5377
|
+
},
|
|
5378
|
+
removeFromKeysList: (allKeys = [], key) => {
|
|
5379
|
+
const index = allKeys.findIndex(item => item.k === key);
|
|
5380
|
+
if (index !== -1) {
|
|
5381
|
+
allKeys.splice(index, 1);
|
|
5376
5382
|
}
|
|
5383
|
+
return index;
|
|
5377
5384
|
}
|
|
5378
5385
|
};
|
|
5379
|
-
|
|
5380
|
-
})();
|
|
5381
|
-
|
|
5382
|
-
if (true) {
|
|
5383
|
-
!(__WEBPACK_AMD_DEFINE_RESULT__ = (function () { return LZString; }).call(exports, __webpack_require__, exports, module),
|
|
5384
|
-
__WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
|
|
5385
|
-
} else {}
|
|
5386
|
-
|
|
5386
|
+
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (utils);
|
|
5387
5387
|
|
|
5388
5388
|
/***/ }),
|
|
5389
5389
|
|