free-be-account 0.0.1
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/crypto.js +927 -0
- package/enum.js +7 -0
- package/index.js +1002 -0
- package/package.json +15 -0
- package/routers/index.js +4 -0
- package/routers/label/index.js +4 -0
- package/routers/label/route.js +33 -0
- package/routers/mgmt/index.js +4 -0
- package/routers/mgmt/route.js +279 -0
- package/routers/org/export/index.js +4 -0
- package/routers/org/export/route.js +11 -0
- package/routers/org/index.js +4 -0
- package/routers/org/route.js +67 -0
- package/routers/perm/index.js +4 -0
- package/routers/perm/route.js +94 -0
- package/routers/uc/index.js +4 -0
- package/routers/uc/info/index.js +4 -0
- package/routers/uc/info/route.js +95 -0
- package/routers/uc/phone/index.js +5 -0
- package/routers/uc/phone/route.js +72 -0
- package/routers/uc/pwd/index.js +4 -0
- package/routers/uc/pwd/route.js +41 -0
- package/routers/uc/sub/index.js +4 -0
- package/routers/uc/sub/route.js +158 -0
- package/sms/index.js +134 -0
- package/test/index.js +1 -0
- package/utils.js +209 -0
package/crypto.js
ADDED
|
@@ -0,0 +1,927 @@
|
|
|
1
|
+
const CryptoJS = require("crypto-js");
|
|
2
|
+
const BCrypt = require('bcrypt');
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* decrypt the encrypted string to the original string
|
|
6
|
+
*
|
|
7
|
+
* return the original string
|
|
8
|
+
*/
|
|
9
|
+
function strDec (data, firstKey, secondKey, thirdKey) {
|
|
10
|
+
let leng = data.length;
|
|
11
|
+
let decStr = "";
|
|
12
|
+
let firstKeyBt, secondKeyBt, thirdKeyBt, firstLength, secondLength, thirdLength;
|
|
13
|
+
if (firstKey != null && firstKey != "") {
|
|
14
|
+
firstKeyBt = getKeyBytes(firstKey);
|
|
15
|
+
firstLength = firstKeyBt.length;
|
|
16
|
+
}
|
|
17
|
+
if (secondKey != null && secondKey != "") {
|
|
18
|
+
secondKeyBt = getKeyBytes(secondKey);
|
|
19
|
+
secondLength = secondKeyBt.length;
|
|
20
|
+
}
|
|
21
|
+
if (thirdKey != null && thirdKey != "") {
|
|
22
|
+
thirdKeyBt = getKeyBytes(thirdKey);
|
|
23
|
+
thirdLength = thirdKeyBt.length;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
let iterator = parseInt(leng / 16);
|
|
27
|
+
let i = 0;
|
|
28
|
+
for (i = 0; i < iterator; i++) {
|
|
29
|
+
let tempData = data.substring(i * 16 + 0, i * 16 + 16);
|
|
30
|
+
let strByte = hexToBt64(tempData);
|
|
31
|
+
let intByte = new Array(64);
|
|
32
|
+
let j = 0;
|
|
33
|
+
for (j = 0; j < 64; j++) {
|
|
34
|
+
intByte[j] = parseInt(strByte.substring(j, j + 1));
|
|
35
|
+
}
|
|
36
|
+
let decByte;
|
|
37
|
+
if (firstKey != null && firstKey != "" && secondKey != null && secondKey != "" && thirdKey != null && thirdKey != "") {
|
|
38
|
+
let tempBt;
|
|
39
|
+
let x, y, z;
|
|
40
|
+
tempBt = intByte;
|
|
41
|
+
for (x = thirdLength - 1; x >= 0; x--) {
|
|
42
|
+
tempBt = dec(tempBt, thirdKeyBt[x]);
|
|
43
|
+
}
|
|
44
|
+
for (y = secondLength - 1; y >= 0; y--) {
|
|
45
|
+
tempBt = dec(tempBt, secondKeyBt[y]);
|
|
46
|
+
}
|
|
47
|
+
for (z = firstLength - 1; z >= 0; z--) {
|
|
48
|
+
tempBt = dec(tempBt, firstKeyBt[z]);
|
|
49
|
+
}
|
|
50
|
+
decByte = tempBt;
|
|
51
|
+
} else {
|
|
52
|
+
if (firstKey != null && firstKey != "" && secondKey != null && secondKey != "") {
|
|
53
|
+
let tempBt;
|
|
54
|
+
let x, y;
|
|
55
|
+
tempBt = intByte;
|
|
56
|
+
for (x = secondLength - 1; x >= 0; x--) {
|
|
57
|
+
tempBt = dec(tempBt, secondKeyBt[x]);
|
|
58
|
+
}
|
|
59
|
+
for (y = firstLength - 1; y >= 0; y--) {
|
|
60
|
+
tempBt = dec(tempBt, firstKeyBt[y]);
|
|
61
|
+
}
|
|
62
|
+
decByte = tempBt;
|
|
63
|
+
} else {
|
|
64
|
+
if (firstKey != null && firstKey != "") {
|
|
65
|
+
let tempBt;
|
|
66
|
+
let x;
|
|
67
|
+
tempBt = intByte;
|
|
68
|
+
for (x = firstLength - 1; x >= 0; x--) {
|
|
69
|
+
tempBt = dec(tempBt, firstKeyBt[x]);
|
|
70
|
+
}
|
|
71
|
+
decByte = tempBt;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
decStr += byteToString(decByte);
|
|
76
|
+
}
|
|
77
|
+
return decStr;
|
|
78
|
+
}
|
|
79
|
+
/*
|
|
80
|
+
* chang the string into the bit array
|
|
81
|
+
*
|
|
82
|
+
* return bit array(it's length % 64 = 0)
|
|
83
|
+
*/
|
|
84
|
+
function getKeyBytes (key) {
|
|
85
|
+
let keyBytes = new Array();
|
|
86
|
+
let leng = key.length;
|
|
87
|
+
let iterator = parseInt(leng / 4);
|
|
88
|
+
let remainder = leng % 4;
|
|
89
|
+
let i = 0;
|
|
90
|
+
for (i = 0; i < iterator; i++) {
|
|
91
|
+
keyBytes[i] = strToBt(key.substring(i * 4 + 0, i * 4 + 4));
|
|
92
|
+
}
|
|
93
|
+
if (remainder > 0) {
|
|
94
|
+
keyBytes[i] = strToBt(key.substring(i * 4 + 0, leng));
|
|
95
|
+
}
|
|
96
|
+
return keyBytes;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/*
|
|
100
|
+
* chang the string(it's length <= 4) into the bit array
|
|
101
|
+
*
|
|
102
|
+
* return bit array(it's length = 64)
|
|
103
|
+
*/
|
|
104
|
+
function strToBt (str) {
|
|
105
|
+
let leng = str.length;
|
|
106
|
+
let bt = new Array(64);
|
|
107
|
+
if (leng < 4) {
|
|
108
|
+
let i = 0, j = 0, p = 0, q = 0;
|
|
109
|
+
for (i = 0; i < leng; i++) {
|
|
110
|
+
let k = str.charCodeAt(i);
|
|
111
|
+
for (j = 0; j < 16; j++) {
|
|
112
|
+
let pow = 1, m = 0;
|
|
113
|
+
for (m = 15; m > j; m--) {
|
|
114
|
+
pow *= 2;
|
|
115
|
+
}
|
|
116
|
+
bt[16 * i + j] = parseInt(k / pow) % 2;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
for (p = leng; p < 4; p++) {
|
|
120
|
+
let k = 0;
|
|
121
|
+
for (q = 0; q < 16; q++) {
|
|
122
|
+
let pow = 1, m = 0;
|
|
123
|
+
for (m = 15; m > q; m--) {
|
|
124
|
+
pow *= 2;
|
|
125
|
+
}
|
|
126
|
+
bt[16 * p + q] = parseInt(k / pow) % 2;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
} else {
|
|
130
|
+
for (let i = 0; i < 4; i++) {
|
|
131
|
+
let k = str.charCodeAt(i);
|
|
132
|
+
for (let j = 0; j < 16; j++) {
|
|
133
|
+
let pow = 1;
|
|
134
|
+
for (let m = 15; m > j; m--) {
|
|
135
|
+
pow *= 2;
|
|
136
|
+
}
|
|
137
|
+
bt[16 * i + j] = parseInt(k / pow) % 2;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return bt;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/*
|
|
145
|
+
* chang the bit(it's length = 4) into the hex
|
|
146
|
+
*
|
|
147
|
+
* return hex
|
|
148
|
+
*/
|
|
149
|
+
function bt4ToHex (binary) {
|
|
150
|
+
let hex;
|
|
151
|
+
switch (binary) {
|
|
152
|
+
case "0000": hex = "0"; break;
|
|
153
|
+
case "0001": hex = "1"; break;
|
|
154
|
+
case "0010": hex = "2"; break;
|
|
155
|
+
case "0011": hex = "3"; break;
|
|
156
|
+
case "0100": hex = "4"; break;
|
|
157
|
+
case "0101": hex = "5"; break;
|
|
158
|
+
case "0110": hex = "6"; break;
|
|
159
|
+
case "0111": hex = "7"; break;
|
|
160
|
+
case "1000": hex = "8"; break;
|
|
161
|
+
case "1001": hex = "9"; break;
|
|
162
|
+
case "1010": hex = "A"; break;
|
|
163
|
+
case "1011": hex = "B"; break;
|
|
164
|
+
case "1100": hex = "C"; break;
|
|
165
|
+
case "1101": hex = "D"; break;
|
|
166
|
+
case "1110": hex = "E"; break;
|
|
167
|
+
case "1111": hex = "F"; break;
|
|
168
|
+
}
|
|
169
|
+
return hex;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/*
|
|
173
|
+
* chang the hex into the bit(it's length = 4)
|
|
174
|
+
*
|
|
175
|
+
* return the bit(it's length = 4)
|
|
176
|
+
*/
|
|
177
|
+
function hexToBt4 (hex) {
|
|
178
|
+
let binary;
|
|
179
|
+
switch (hex) {
|
|
180
|
+
case "0": binary = "0000"; break;
|
|
181
|
+
case "1": binary = "0001"; break;
|
|
182
|
+
case "2": binary = "0010"; break;
|
|
183
|
+
case "3": binary = "0011"; break;
|
|
184
|
+
case "4": binary = "0100"; break;
|
|
185
|
+
case "5": binary = "0101"; break;
|
|
186
|
+
case "6": binary = "0110"; break;
|
|
187
|
+
case "7": binary = "0111"; break;
|
|
188
|
+
case "8": binary = "1000"; break;
|
|
189
|
+
case "9": binary = "1001"; break;
|
|
190
|
+
case "A": binary = "1010"; break;
|
|
191
|
+
case "B": binary = "1011"; break;
|
|
192
|
+
case "C": binary = "1100"; break;
|
|
193
|
+
case "D": binary = "1101"; break;
|
|
194
|
+
case "E": binary = "1110"; break;
|
|
195
|
+
case "F": binary = "1111"; break;
|
|
196
|
+
}
|
|
197
|
+
return binary;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/*
|
|
201
|
+
* chang the bit(it's length = 64) into the string
|
|
202
|
+
*
|
|
203
|
+
* return string
|
|
204
|
+
*/
|
|
205
|
+
function byteToString (byteData) {
|
|
206
|
+
let str = "";
|
|
207
|
+
for (let i = 0; i < 4; i++) {
|
|
208
|
+
let count = 0;
|
|
209
|
+
for (let j = 0; j < 16; j++) {
|
|
210
|
+
let pow = 1;
|
|
211
|
+
for (let m = 15; m > j; m--) {
|
|
212
|
+
pow *= 2;
|
|
213
|
+
}
|
|
214
|
+
count += byteData[16 * i + j] * pow;
|
|
215
|
+
}
|
|
216
|
+
if (count != 0) {
|
|
217
|
+
str += String.fromCharCode(count);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return str;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function bt64ToHex (byteData) {
|
|
224
|
+
let hex = "";
|
|
225
|
+
for (let i = 0; i < 16; i++) {
|
|
226
|
+
let bt = "";
|
|
227
|
+
for (let j = 0; j < 4; j++) {
|
|
228
|
+
bt += byteData[i * 4 + j];
|
|
229
|
+
}
|
|
230
|
+
hex += bt4ToHex(bt);
|
|
231
|
+
}
|
|
232
|
+
return hex;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function hexToBt64 (hex) {
|
|
236
|
+
let binary = "";
|
|
237
|
+
for (let i = 0; i < 16; i++) {
|
|
238
|
+
binary += hexToBt4(hex.substring(i, i + 1));
|
|
239
|
+
}
|
|
240
|
+
return binary;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/*
|
|
244
|
+
* the 64 bit des core arithmetic
|
|
245
|
+
*/
|
|
246
|
+
|
|
247
|
+
function enc (dataByte, keyByte) {
|
|
248
|
+
let keys = generateKeys(keyByte);
|
|
249
|
+
let ipByte = initPermute(dataByte);
|
|
250
|
+
let ipLeft = new Array(32);
|
|
251
|
+
let ipRight = new Array(32);
|
|
252
|
+
let tempLeft = new Array(32);
|
|
253
|
+
let i = 0, j = 0, k = 0, m = 0, n = 0;
|
|
254
|
+
for (k = 0; k < 32; k++) {
|
|
255
|
+
ipLeft[k] = ipByte[k];
|
|
256
|
+
ipRight[k] = ipByte[32 + k];
|
|
257
|
+
}
|
|
258
|
+
for (i = 0; i < 16; i++) {
|
|
259
|
+
for (j = 0; j < 32; j++) {
|
|
260
|
+
tempLeft[j] = ipLeft[j];
|
|
261
|
+
ipLeft[j] = ipRight[j];
|
|
262
|
+
}
|
|
263
|
+
let key = new Array(48);
|
|
264
|
+
for (m = 0; m < 48; m++) {
|
|
265
|
+
key[m] = keys[i][m];
|
|
266
|
+
}
|
|
267
|
+
let tempRight = xor(pPermute(sBoxPermute(xor(expandPermute(ipRight), key))), tempLeft);
|
|
268
|
+
for (n = 0; n < 32; n++) {
|
|
269
|
+
ipRight[n] = tempRight[n];
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
let finalData = new Array(64);
|
|
276
|
+
for (i = 0; i < 32; i++) {
|
|
277
|
+
finalData[i] = ipRight[i];
|
|
278
|
+
finalData[32 + i] = ipLeft[i];
|
|
279
|
+
}
|
|
280
|
+
return finallyPermute(finalData);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function dec (dataByte, keyByte) {
|
|
284
|
+
let keys = generateKeys(keyByte);
|
|
285
|
+
let ipByte = initPermute(dataByte);
|
|
286
|
+
let ipLeft = new Array(32);
|
|
287
|
+
let ipRight = new Array(32);
|
|
288
|
+
let tempLeft = new Array(32);
|
|
289
|
+
let i = 0, j = 0, k = 0, m = 0, n = 0;
|
|
290
|
+
for (k = 0; k < 32; k++) {
|
|
291
|
+
ipLeft[k] = ipByte[k];
|
|
292
|
+
ipRight[k] = ipByte[32 + k];
|
|
293
|
+
}
|
|
294
|
+
for (i = 15; i >= 0; i--) {
|
|
295
|
+
for (j = 0; j < 32; j++) {
|
|
296
|
+
tempLeft[j] = ipLeft[j];
|
|
297
|
+
ipLeft[j] = ipRight[j];
|
|
298
|
+
}
|
|
299
|
+
let key = new Array(48);
|
|
300
|
+
for (m = 0; m < 48; m++) {
|
|
301
|
+
key[m] = keys[i][m];
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
let tempRight = xor(pPermute(sBoxPermute(xor(expandPermute(ipRight), key))), tempLeft);
|
|
305
|
+
for (n = 0; n < 32; n++) {
|
|
306
|
+
ipRight[n] = tempRight[n];
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
let finalData = new Array(64);
|
|
312
|
+
for (i = 0; i < 32; i++) {
|
|
313
|
+
finalData[i] = ipRight[i];
|
|
314
|
+
finalData[32 + i] = ipLeft[i];
|
|
315
|
+
}
|
|
316
|
+
return finallyPermute(finalData);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function initPermute (originalData) {
|
|
320
|
+
let ipByte = new Array(64);
|
|
321
|
+
for (let i = 0, m = 1, n = 0; i < 4; i++, m += 2, n += 2) {
|
|
322
|
+
for (let j = 7, k = 0; j >= 0; j--, k++) {
|
|
323
|
+
ipByte[i * 8 + k] = originalData[j * 8 + m];
|
|
324
|
+
ipByte[i * 8 + k + 32] = originalData[j * 8 + n];
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
return ipByte;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function expandPermute (rightData) {
|
|
331
|
+
let epByte = new Array(48);
|
|
332
|
+
for (let i = 0; i < 8; i++) {
|
|
333
|
+
if (i == 0) {
|
|
334
|
+
epByte[i * 6 + 0] = rightData[31];
|
|
335
|
+
} else {
|
|
336
|
+
epByte[i * 6 + 0] = rightData[i * 4 - 1];
|
|
337
|
+
}
|
|
338
|
+
epByte[i * 6 + 1] = rightData[i * 4 + 0];
|
|
339
|
+
epByte[i * 6 + 2] = rightData[i * 4 + 1];
|
|
340
|
+
epByte[i * 6 + 3] = rightData[i * 4 + 2];
|
|
341
|
+
epByte[i * 6 + 4] = rightData[i * 4 + 3];
|
|
342
|
+
if (i == 7) {
|
|
343
|
+
epByte[i * 6 + 5] = rightData[0];
|
|
344
|
+
} else {
|
|
345
|
+
epByte[i * 6 + 5] = rightData[i * 4 + 4];
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
return epByte;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
function xor (byteOne, byteTwo) {
|
|
352
|
+
let xorByte = new Array(byteOne.length);
|
|
353
|
+
for (let i = 0; i < byteOne.length; i++) {
|
|
354
|
+
xorByte[i] = byteOne[i] ^ byteTwo[i];
|
|
355
|
+
}
|
|
356
|
+
return xorByte;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
function sBoxPermute (expandByte) {
|
|
360
|
+
|
|
361
|
+
let sBoxByte = new Array(32);
|
|
362
|
+
let binary = "";
|
|
363
|
+
let s1 = [
|
|
364
|
+
[14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7],
|
|
365
|
+
[0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8],
|
|
366
|
+
[4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0],
|
|
367
|
+
[15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13]];
|
|
368
|
+
|
|
369
|
+
/* Table - s2 */
|
|
370
|
+
let s2 = [
|
|
371
|
+
[15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10],
|
|
372
|
+
[3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5],
|
|
373
|
+
[0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15],
|
|
374
|
+
[13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9]];
|
|
375
|
+
|
|
376
|
+
/* Table - s3 */
|
|
377
|
+
let s3 = [
|
|
378
|
+
[10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8],
|
|
379
|
+
[13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1],
|
|
380
|
+
[13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7],
|
|
381
|
+
[1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12]];
|
|
382
|
+
/* Table - s4 */
|
|
383
|
+
let s4 = [
|
|
384
|
+
[7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15],
|
|
385
|
+
[13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9],
|
|
386
|
+
[10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4],
|
|
387
|
+
[3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14]];
|
|
388
|
+
|
|
389
|
+
/* Table - s5 */
|
|
390
|
+
let s5 = [
|
|
391
|
+
[2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9],
|
|
392
|
+
[14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6],
|
|
393
|
+
[4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14],
|
|
394
|
+
[11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3]];
|
|
395
|
+
|
|
396
|
+
/* Table - s6 */
|
|
397
|
+
let s6 = [
|
|
398
|
+
[12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11],
|
|
399
|
+
[10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8],
|
|
400
|
+
[9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6],
|
|
401
|
+
[4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13]];
|
|
402
|
+
|
|
403
|
+
/* Table - s7 */
|
|
404
|
+
let s7 = [
|
|
405
|
+
[4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1],
|
|
406
|
+
[13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6],
|
|
407
|
+
[1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2],
|
|
408
|
+
[6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12]];
|
|
409
|
+
|
|
410
|
+
/* Table - s8 */
|
|
411
|
+
let s8 = [
|
|
412
|
+
[13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7],
|
|
413
|
+
[1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2],
|
|
414
|
+
[7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8],
|
|
415
|
+
[2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11]];
|
|
416
|
+
|
|
417
|
+
for (let m = 0; m < 8; m++) {
|
|
418
|
+
let i = 0, j = 0;
|
|
419
|
+
i = expandByte[m * 6 + 0] * 2 + expandByte[m * 6 + 5];
|
|
420
|
+
j = expandByte[m * 6 + 1] * 2 * 2 * 2
|
|
421
|
+
+ expandByte[m * 6 + 2] * 2 * 2
|
|
422
|
+
+ expandByte[m * 6 + 3] * 2
|
|
423
|
+
+ expandByte[m * 6 + 4];
|
|
424
|
+
switch (m) {
|
|
425
|
+
case 0:
|
|
426
|
+
binary = getBoxBinary(s1[i][j]);
|
|
427
|
+
break;
|
|
428
|
+
case 1:
|
|
429
|
+
binary = getBoxBinary(s2[i][j]);
|
|
430
|
+
break;
|
|
431
|
+
case 2:
|
|
432
|
+
binary = getBoxBinary(s3[i][j]);
|
|
433
|
+
break;
|
|
434
|
+
case 3:
|
|
435
|
+
binary = getBoxBinary(s4[i][j]);
|
|
436
|
+
break;
|
|
437
|
+
case 4:
|
|
438
|
+
binary = getBoxBinary(s5[i][j]);
|
|
439
|
+
break;
|
|
440
|
+
case 5:
|
|
441
|
+
binary = getBoxBinary(s6[i][j]);
|
|
442
|
+
break;
|
|
443
|
+
case 6:
|
|
444
|
+
binary = getBoxBinary(s7[i][j]);
|
|
445
|
+
break;
|
|
446
|
+
case 7:
|
|
447
|
+
binary = getBoxBinary(s8[i][j]);
|
|
448
|
+
break;
|
|
449
|
+
}
|
|
450
|
+
sBoxByte[m * 4 + 0] = parseInt(binary.substring(0, 1));
|
|
451
|
+
sBoxByte[m * 4 + 1] = parseInt(binary.substring(1, 2));
|
|
452
|
+
sBoxByte[m * 4 + 2] = parseInt(binary.substring(2, 3));
|
|
453
|
+
sBoxByte[m * 4 + 3] = parseInt(binary.substring(3, 4));
|
|
454
|
+
}
|
|
455
|
+
return sBoxByte;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
function pPermute (sBoxByte) {
|
|
459
|
+
let pBoxPermute = new Array(32);
|
|
460
|
+
pBoxPermute[0] = sBoxByte[15];
|
|
461
|
+
pBoxPermute[1] = sBoxByte[6];
|
|
462
|
+
pBoxPermute[2] = sBoxByte[19];
|
|
463
|
+
pBoxPermute[3] = sBoxByte[20];
|
|
464
|
+
pBoxPermute[4] = sBoxByte[28];
|
|
465
|
+
pBoxPermute[5] = sBoxByte[11];
|
|
466
|
+
pBoxPermute[6] = sBoxByte[27];
|
|
467
|
+
pBoxPermute[7] = sBoxByte[16];
|
|
468
|
+
pBoxPermute[8] = sBoxByte[0];
|
|
469
|
+
pBoxPermute[9] = sBoxByte[14];
|
|
470
|
+
pBoxPermute[10] = sBoxByte[22];
|
|
471
|
+
pBoxPermute[11] = sBoxByte[25];
|
|
472
|
+
pBoxPermute[12] = sBoxByte[4];
|
|
473
|
+
pBoxPermute[13] = sBoxByte[17];
|
|
474
|
+
pBoxPermute[14] = sBoxByte[30];
|
|
475
|
+
pBoxPermute[15] = sBoxByte[9];
|
|
476
|
+
pBoxPermute[16] = sBoxByte[1];
|
|
477
|
+
pBoxPermute[17] = sBoxByte[7];
|
|
478
|
+
pBoxPermute[18] = sBoxByte[23];
|
|
479
|
+
pBoxPermute[19] = sBoxByte[13];
|
|
480
|
+
pBoxPermute[20] = sBoxByte[31];
|
|
481
|
+
pBoxPermute[21] = sBoxByte[26];
|
|
482
|
+
pBoxPermute[22] = sBoxByte[2];
|
|
483
|
+
pBoxPermute[23] = sBoxByte[8];
|
|
484
|
+
pBoxPermute[24] = sBoxByte[18];
|
|
485
|
+
pBoxPermute[25] = sBoxByte[12];
|
|
486
|
+
pBoxPermute[26] = sBoxByte[29];
|
|
487
|
+
pBoxPermute[27] = sBoxByte[5];
|
|
488
|
+
pBoxPermute[28] = sBoxByte[21];
|
|
489
|
+
pBoxPermute[29] = sBoxByte[10];
|
|
490
|
+
pBoxPermute[30] = sBoxByte[3];
|
|
491
|
+
pBoxPermute[31] = sBoxByte[24];
|
|
492
|
+
return pBoxPermute;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
function finallyPermute (endByte) {
|
|
496
|
+
let fpByte = new Array(64);
|
|
497
|
+
fpByte[0] = endByte[39];
|
|
498
|
+
fpByte[1] = endByte[7];
|
|
499
|
+
fpByte[2] = endByte[47];
|
|
500
|
+
fpByte[3] = endByte[15];
|
|
501
|
+
fpByte[4] = endByte[55];
|
|
502
|
+
fpByte[5] = endByte[23];
|
|
503
|
+
fpByte[6] = endByte[63];
|
|
504
|
+
fpByte[7] = endByte[31];
|
|
505
|
+
fpByte[8] = endByte[38];
|
|
506
|
+
fpByte[9] = endByte[6];
|
|
507
|
+
fpByte[10] = endByte[46];
|
|
508
|
+
fpByte[11] = endByte[14];
|
|
509
|
+
fpByte[12] = endByte[54];
|
|
510
|
+
fpByte[13] = endByte[22];
|
|
511
|
+
fpByte[14] = endByte[62];
|
|
512
|
+
fpByte[15] = endByte[30];
|
|
513
|
+
fpByte[16] = endByte[37];
|
|
514
|
+
fpByte[17] = endByte[5];
|
|
515
|
+
fpByte[18] = endByte[45];
|
|
516
|
+
fpByte[19] = endByte[13];
|
|
517
|
+
fpByte[20] = endByte[53];
|
|
518
|
+
fpByte[21] = endByte[21];
|
|
519
|
+
fpByte[22] = endByte[61];
|
|
520
|
+
fpByte[23] = endByte[29];
|
|
521
|
+
fpByte[24] = endByte[36];
|
|
522
|
+
fpByte[25] = endByte[4];
|
|
523
|
+
fpByte[26] = endByte[44];
|
|
524
|
+
fpByte[27] = endByte[12];
|
|
525
|
+
fpByte[28] = endByte[52];
|
|
526
|
+
fpByte[29] = endByte[20];
|
|
527
|
+
fpByte[30] = endByte[60];
|
|
528
|
+
fpByte[31] = endByte[28];
|
|
529
|
+
fpByte[32] = endByte[35];
|
|
530
|
+
fpByte[33] = endByte[3];
|
|
531
|
+
fpByte[34] = endByte[43];
|
|
532
|
+
fpByte[35] = endByte[11];
|
|
533
|
+
fpByte[36] = endByte[51];
|
|
534
|
+
fpByte[37] = endByte[19];
|
|
535
|
+
fpByte[38] = endByte[59];
|
|
536
|
+
fpByte[39] = endByte[27];
|
|
537
|
+
fpByte[40] = endByte[34];
|
|
538
|
+
fpByte[41] = endByte[2];
|
|
539
|
+
fpByte[42] = endByte[42];
|
|
540
|
+
fpByte[43] = endByte[10];
|
|
541
|
+
fpByte[44] = endByte[50];
|
|
542
|
+
fpByte[45] = endByte[18];
|
|
543
|
+
fpByte[46] = endByte[58];
|
|
544
|
+
fpByte[47] = endByte[26];
|
|
545
|
+
fpByte[48] = endByte[33];
|
|
546
|
+
fpByte[49] = endByte[1];
|
|
547
|
+
fpByte[50] = endByte[41];
|
|
548
|
+
fpByte[51] = endByte[9];
|
|
549
|
+
fpByte[52] = endByte[49];
|
|
550
|
+
fpByte[53] = endByte[17];
|
|
551
|
+
fpByte[54] = endByte[57];
|
|
552
|
+
fpByte[55] = endByte[25];
|
|
553
|
+
fpByte[56] = endByte[32];
|
|
554
|
+
fpByte[57] = endByte[0];
|
|
555
|
+
fpByte[58] = endByte[40];
|
|
556
|
+
fpByte[59] = endByte[8];
|
|
557
|
+
fpByte[60] = endByte[48];
|
|
558
|
+
fpByte[61] = endByte[16];
|
|
559
|
+
fpByte[62] = endByte[56];
|
|
560
|
+
fpByte[63] = endByte[24];
|
|
561
|
+
return fpByte;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
function getBoxBinary (i) {
|
|
565
|
+
let binary = "";
|
|
566
|
+
switch (i) {
|
|
567
|
+
case 0: binary = "0000"; break;
|
|
568
|
+
case 1: binary = "0001"; break;
|
|
569
|
+
case 2: binary = "0010"; break;
|
|
570
|
+
case 3: binary = "0011"; break;
|
|
571
|
+
case 4: binary = "0100"; break;
|
|
572
|
+
case 5: binary = "0101"; break;
|
|
573
|
+
case 6: binary = "0110"; break;
|
|
574
|
+
case 7: binary = "0111"; break;
|
|
575
|
+
case 8: binary = "1000"; break;
|
|
576
|
+
case 9: binary = "1001"; break;
|
|
577
|
+
case 10: binary = "1010"; break;
|
|
578
|
+
case 11: binary = "1011"; break;
|
|
579
|
+
case 12: binary = "1100"; break;
|
|
580
|
+
case 13: binary = "1101"; break;
|
|
581
|
+
case 14: binary = "1110"; break;
|
|
582
|
+
case 15: binary = "1111"; break;
|
|
583
|
+
}
|
|
584
|
+
return binary;
|
|
585
|
+
}
|
|
586
|
+
/*
|
|
587
|
+
* generate 16 keys for xor
|
|
588
|
+
*
|
|
589
|
+
*/
|
|
590
|
+
function generateKeys (keyByte) {
|
|
591
|
+
let key = new Array(56);
|
|
592
|
+
let keys = new Array();
|
|
593
|
+
|
|
594
|
+
keys[0] = new Array();
|
|
595
|
+
keys[1] = new Array();
|
|
596
|
+
keys[2] = new Array();
|
|
597
|
+
keys[3] = new Array();
|
|
598
|
+
keys[4] = new Array();
|
|
599
|
+
keys[5] = new Array();
|
|
600
|
+
keys[6] = new Array();
|
|
601
|
+
keys[7] = new Array();
|
|
602
|
+
keys[8] = new Array();
|
|
603
|
+
keys[9] = new Array();
|
|
604
|
+
keys[10] = new Array();
|
|
605
|
+
keys[11] = new Array();
|
|
606
|
+
keys[12] = new Array();
|
|
607
|
+
keys[13] = new Array();
|
|
608
|
+
keys[14] = new Array();
|
|
609
|
+
keys[15] = new Array();
|
|
610
|
+
let loop = [1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1];
|
|
611
|
+
|
|
612
|
+
for (let i = 0; i < 7; i++) {
|
|
613
|
+
for (let j = 0, k = 7; j < 8; j++, k--) {
|
|
614
|
+
key[i * 8 + j] = keyByte[8 * k + i];
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
let i = 0;
|
|
619
|
+
for (i = 0; i < 16; i++) {
|
|
620
|
+
let tempLeft = 0;
|
|
621
|
+
let tempRight = 0;
|
|
622
|
+
for (let j = 0; j < loop[i]; j++) {
|
|
623
|
+
tempLeft = key[0];
|
|
624
|
+
tempRight = key[28];
|
|
625
|
+
for (let k = 0; k < 27; k++) {
|
|
626
|
+
key[k] = key[k + 1];
|
|
627
|
+
key[28 + k] = key[29 + k];
|
|
628
|
+
}
|
|
629
|
+
key[27] = tempLeft;
|
|
630
|
+
key[55] = tempRight;
|
|
631
|
+
}
|
|
632
|
+
let tempKey = new Array(48);
|
|
633
|
+
tempKey[0] = key[13];
|
|
634
|
+
tempKey[1] = key[16];
|
|
635
|
+
tempKey[2] = key[10];
|
|
636
|
+
tempKey[3] = key[23];
|
|
637
|
+
tempKey[4] = key[0];
|
|
638
|
+
tempKey[5] = key[4];
|
|
639
|
+
tempKey[6] = key[2];
|
|
640
|
+
tempKey[7] = key[27];
|
|
641
|
+
tempKey[8] = key[14];
|
|
642
|
+
tempKey[9] = key[5];
|
|
643
|
+
tempKey[10] = key[20];
|
|
644
|
+
tempKey[11] = key[9];
|
|
645
|
+
tempKey[12] = key[22];
|
|
646
|
+
tempKey[13] = key[18];
|
|
647
|
+
tempKey[14] = key[11];
|
|
648
|
+
tempKey[15] = key[3];
|
|
649
|
+
tempKey[16] = key[25];
|
|
650
|
+
tempKey[17] = key[7];
|
|
651
|
+
tempKey[18] = key[15];
|
|
652
|
+
tempKey[19] = key[6];
|
|
653
|
+
tempKey[20] = key[26];
|
|
654
|
+
tempKey[21] = key[19];
|
|
655
|
+
tempKey[22] = key[12];
|
|
656
|
+
tempKey[23] = key[1];
|
|
657
|
+
tempKey[24] = key[40];
|
|
658
|
+
tempKey[25] = key[51];
|
|
659
|
+
tempKey[26] = key[30];
|
|
660
|
+
tempKey[27] = key[36];
|
|
661
|
+
tempKey[28] = key[46];
|
|
662
|
+
tempKey[29] = key[54];
|
|
663
|
+
tempKey[30] = key[29];
|
|
664
|
+
tempKey[31] = key[39];
|
|
665
|
+
tempKey[32] = key[50];
|
|
666
|
+
tempKey[33] = key[44];
|
|
667
|
+
tempKey[34] = key[32];
|
|
668
|
+
tempKey[35] = key[47];
|
|
669
|
+
tempKey[36] = key[43];
|
|
670
|
+
tempKey[37] = key[48];
|
|
671
|
+
tempKey[38] = key[38];
|
|
672
|
+
tempKey[39] = key[55];
|
|
673
|
+
tempKey[40] = key[33];
|
|
674
|
+
tempKey[41] = key[52];
|
|
675
|
+
tempKey[42] = key[45];
|
|
676
|
+
tempKey[43] = key[41];
|
|
677
|
+
tempKey[44] = key[49];
|
|
678
|
+
tempKey[45] = key[35];
|
|
679
|
+
tempKey[46] = key[28];
|
|
680
|
+
tempKey[47] = key[31];
|
|
681
|
+
switch (i) {
|
|
682
|
+
case 0: for (let m = 0; m < 48; m++) { keys[0][m] = tempKey[m]; } break;
|
|
683
|
+
case 1: for (let m = 0; m < 48; m++) { keys[1][m] = tempKey[m]; } break;
|
|
684
|
+
case 2: for (let m = 0; m < 48; m++) { keys[2][m] = tempKey[m]; } break;
|
|
685
|
+
case 3: for (let m = 0; m < 48; m++) { keys[3][m] = tempKey[m]; } break;
|
|
686
|
+
case 4: for (let m = 0; m < 48; m++) { keys[4][m] = tempKey[m]; } break;
|
|
687
|
+
case 5: for (let m = 0; m < 48; m++) { keys[5][m] = tempKey[m]; } break;
|
|
688
|
+
case 6: for (let m = 0; m < 48; m++) { keys[6][m] = tempKey[m]; } break;
|
|
689
|
+
case 7: for (let m = 0; m < 48; m++) { keys[7][m] = tempKey[m]; } break;
|
|
690
|
+
case 8: for (let m = 0; m < 48; m++) { keys[8][m] = tempKey[m]; } break;
|
|
691
|
+
case 9: for (let m = 0; m < 48; m++) { keys[9][m] = tempKey[m]; } break;
|
|
692
|
+
case 10: for (let m = 0; m < 48; m++) { keys[10][m] = tempKey[m]; } break;
|
|
693
|
+
case 11: for (let m = 0; m < 48; m++) { keys[11][m] = tempKey[m]; } break;
|
|
694
|
+
case 12: for (let m = 0; m < 48; m++) { keys[12][m] = tempKey[m]; } break;
|
|
695
|
+
case 13: for (let m = 0; m < 48; m++) { keys[13][m] = tempKey[m]; } break;
|
|
696
|
+
case 14: for (let m = 0; m < 48; m++) { keys[14][m] = tempKey[m]; } break;
|
|
697
|
+
case 15: for (let m = 0; m < 48; m++) { keys[15][m] = tempKey[m]; } break;
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
return keys;
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
/*
|
|
704
|
+
* encrypt the string to string made up of hex
|
|
705
|
+
* return the encrypted string
|
|
706
|
+
*/
|
|
707
|
+
function strEnc (data, firstKey, secondKey, thirdKey) {
|
|
708
|
+
|
|
709
|
+
let leng = data.length;
|
|
710
|
+
let encData = "";
|
|
711
|
+
let firstKeyBt, secondKeyBt, thirdKeyBt, firstLength, secondLength, thirdLength;
|
|
712
|
+
if (firstKey != null && firstKey != "") {
|
|
713
|
+
firstKeyBt = getKeyBytes(firstKey);
|
|
714
|
+
firstLength = firstKeyBt.length;
|
|
715
|
+
}
|
|
716
|
+
if (secondKey != null && secondKey != "") {
|
|
717
|
+
secondKeyBt = getKeyBytes(secondKey);
|
|
718
|
+
secondLength = secondKeyBt.length;
|
|
719
|
+
}
|
|
720
|
+
if (thirdKey != null && thirdKey != "") {
|
|
721
|
+
thirdKeyBt = getKeyBytes(thirdKey);
|
|
722
|
+
thirdLength = thirdKeyBt.length;
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
if (leng > 0) {
|
|
726
|
+
if (leng < 4) {
|
|
727
|
+
let bt = strToBt(data);
|
|
728
|
+
let encByte;
|
|
729
|
+
if (firstKey != null && firstKey != "" && secondKey != null && secondKey != "" && thirdKey != null && thirdKey != "") {
|
|
730
|
+
let tempBt;
|
|
731
|
+
let x, y, z;
|
|
732
|
+
tempBt = bt;
|
|
733
|
+
for (x = 0; x < firstLength; x++) {
|
|
734
|
+
tempBt = enc(tempBt, firstKeyBt[x]);
|
|
735
|
+
}
|
|
736
|
+
for (y = 0; y < secondLength; y++) {
|
|
737
|
+
tempBt = enc(tempBt, secondKeyBt[y]);
|
|
738
|
+
}
|
|
739
|
+
for (z = 0; z < thirdLength; z++) {
|
|
740
|
+
tempBt = enc(tempBt, thirdKeyBt[z]);
|
|
741
|
+
}
|
|
742
|
+
encByte = tempBt;
|
|
743
|
+
} else {
|
|
744
|
+
if (firstKey != null && firstKey != "" && secondKey != null && secondKey != "") {
|
|
745
|
+
let tempBt;
|
|
746
|
+
let x, y;
|
|
747
|
+
tempBt = bt;
|
|
748
|
+
for (x = 0; x < firstLength; x++) {
|
|
749
|
+
tempBt = enc(tempBt, firstKeyBt[x]);
|
|
750
|
+
}
|
|
751
|
+
for (y = 0; y < secondLength; y++) {
|
|
752
|
+
tempBt = enc(tempBt, secondKeyBt[y]);
|
|
753
|
+
}
|
|
754
|
+
encByte = tempBt;
|
|
755
|
+
} else {
|
|
756
|
+
if (firstKey != null && firstKey != "") {
|
|
757
|
+
let tempBt;
|
|
758
|
+
let x = 0;
|
|
759
|
+
tempBt = bt;
|
|
760
|
+
for (x = 0; x < firstLength; x++) {
|
|
761
|
+
tempBt = enc(tempBt, firstKeyBt[x]);
|
|
762
|
+
}
|
|
763
|
+
encByte = tempBt;
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
encData = bt64ToHex(encByte);
|
|
768
|
+
} else {
|
|
769
|
+
let iterator = parseInt(leng / 4);
|
|
770
|
+
let remainder = leng % 4;
|
|
771
|
+
let i = 0;
|
|
772
|
+
for (i = 0; i < iterator; i++) {
|
|
773
|
+
let tempData = data.substring(i * 4 + 0, i * 4 + 4);
|
|
774
|
+
let tempByte = strToBt(tempData);
|
|
775
|
+
let encByte;
|
|
776
|
+
if (firstKey != null && firstKey != "" && secondKey != null && secondKey != "" && thirdKey != null && thirdKey != "") {
|
|
777
|
+
let tempBt;
|
|
778
|
+
let x, y, z;
|
|
779
|
+
tempBt = tempByte;
|
|
780
|
+
for (x = 0; x < firstLength; x++) {
|
|
781
|
+
tempBt = enc(tempBt, firstKeyBt[x]);
|
|
782
|
+
}
|
|
783
|
+
for (y = 0; y < secondLength; y++) {
|
|
784
|
+
tempBt = enc(tempBt, secondKeyBt[y]);
|
|
785
|
+
}
|
|
786
|
+
for (z = 0; z < thirdLength; z++) {
|
|
787
|
+
tempBt = enc(tempBt, thirdKeyBt[z]);
|
|
788
|
+
}
|
|
789
|
+
encByte = tempBt;
|
|
790
|
+
} else {
|
|
791
|
+
if (firstKey != null && firstKey != "" && secondKey != null && secondKey != "") {
|
|
792
|
+
let tempBt;
|
|
793
|
+
let x, y;
|
|
794
|
+
tempBt = tempByte;
|
|
795
|
+
for (x = 0; x < firstLength; x++) {
|
|
796
|
+
tempBt = enc(tempBt, firstKeyBt[x]);
|
|
797
|
+
}
|
|
798
|
+
for (y = 0; y < secondLength; y++) {
|
|
799
|
+
tempBt = enc(tempBt, secondKeyBt[y]);
|
|
800
|
+
}
|
|
801
|
+
encByte = tempBt;
|
|
802
|
+
} else {
|
|
803
|
+
if (firstKey != null && firstKey != "") {
|
|
804
|
+
let tempBt;
|
|
805
|
+
let x;
|
|
806
|
+
tempBt = tempByte;
|
|
807
|
+
for (x = 0; x < firstLength; x++) {
|
|
808
|
+
tempBt = enc(tempBt, firstKeyBt[x]);
|
|
809
|
+
}
|
|
810
|
+
encByte = tempBt;
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
encData += bt64ToHex(encByte);
|
|
815
|
+
}
|
|
816
|
+
if (remainder > 0) {
|
|
817
|
+
let remainderData = data.substring(iterator * 4 + 0, leng);
|
|
818
|
+
let tempByte = strToBt(remainderData);
|
|
819
|
+
let encByte;
|
|
820
|
+
if (firstKey != null && firstKey != "" && secondKey != null && secondKey != "" && thirdKey != null && thirdKey != "") {
|
|
821
|
+
let tempBt;
|
|
822
|
+
let x, y, z;
|
|
823
|
+
tempBt = tempByte;
|
|
824
|
+
for (x = 0; x < firstLength; x++) {
|
|
825
|
+
tempBt = enc(tempBt, firstKeyBt[x]);
|
|
826
|
+
}
|
|
827
|
+
for (y = 0; y < secondLength; y++) {
|
|
828
|
+
tempBt = enc(tempBt, secondKeyBt[y]);
|
|
829
|
+
}
|
|
830
|
+
for (z = 0; z < thirdLength; z++) {
|
|
831
|
+
tempBt = enc(tempBt, thirdKeyBt[z]);
|
|
832
|
+
}
|
|
833
|
+
encByte = tempBt;
|
|
834
|
+
} else {
|
|
835
|
+
if (firstKey != null && firstKey != "" && secondKey != null && secondKey != "") {
|
|
836
|
+
let tempBt;
|
|
837
|
+
let x, y;
|
|
838
|
+
tempBt = tempByte;
|
|
839
|
+
for (x = 0; x < firstLength; x++) {
|
|
840
|
+
tempBt = enc(tempBt, firstKeyBt[x]);
|
|
841
|
+
}
|
|
842
|
+
for (y = 0; y < secondLength; y++) {
|
|
843
|
+
tempBt = enc(tempBt, secondKeyBt[y]);
|
|
844
|
+
}
|
|
845
|
+
encByte = tempBt;
|
|
846
|
+
} else {
|
|
847
|
+
if (firstKey != null && firstKey != "") {
|
|
848
|
+
let tempBt;
|
|
849
|
+
let x;
|
|
850
|
+
tempBt = tempByte;
|
|
851
|
+
for (x = 0; x < firstLength; x++) {
|
|
852
|
+
tempBt = enc(tempBt, firstKeyBt[x]);
|
|
853
|
+
}
|
|
854
|
+
encByte = tempBt;
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
encData += bt64ToHex(encByte);
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
return encData;
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
const crypto = {
|
|
866
|
+
MD5: function (d) {
|
|
867
|
+
return CryptoJS.MD5(d).toString();
|
|
868
|
+
},
|
|
869
|
+
randomPassword: (len) => {
|
|
870
|
+
const chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
|
|
871
|
+
var result = '';
|
|
872
|
+
for (var i = len; i > 0; --i) {
|
|
873
|
+
result += chars[Math.floor(Math.random() * chars.length)];
|
|
874
|
+
}
|
|
875
|
+
return result;
|
|
876
|
+
},
|
|
877
|
+
generateSalt: (l = 16) => {
|
|
878
|
+
return CryptoJS.lib.WordArray.random(l);
|
|
879
|
+
},
|
|
880
|
+
sha1: (input, salt, iterations) => {
|
|
881
|
+
const digest = CryptoJS.algo.SHA1.create();
|
|
882
|
+
|
|
883
|
+
if (salt != null) {
|
|
884
|
+
digest.update(CryptoJS.enc.Hex.parse(salt));
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
digest.update(CryptoJS.enc.Utf8.parse(input));
|
|
888
|
+
let result = digest.finalize();
|
|
889
|
+
|
|
890
|
+
for (let i = 1; i < iterations; i++) {
|
|
891
|
+
digest.reset();
|
|
892
|
+
digest.update(result);
|
|
893
|
+
result = digest.finalize();
|
|
894
|
+
}
|
|
895
|
+
return result;
|
|
896
|
+
},
|
|
897
|
+
bcrypt: (input, round = 10) => {
|
|
898
|
+
return BCrypt.hashSync(input, round);
|
|
899
|
+
},
|
|
900
|
+
bcryptVerify: (input, hash) => {
|
|
901
|
+
return BCrypt.compareSync(input, hash);
|
|
902
|
+
},
|
|
903
|
+
encoder: {
|
|
904
|
+
desEncode: function (data, secretKey) {
|
|
905
|
+
if (data && secretKey) {
|
|
906
|
+
let ks = secretKey.split(',');
|
|
907
|
+
if (ks.length >= 3) {
|
|
908
|
+
return strEnc(data, ks[0], ks[1], ks[2]);
|
|
909
|
+
}
|
|
910
|
+
return strEnc(data, secretKey, '', '');
|
|
911
|
+
}
|
|
912
|
+
return '';
|
|
913
|
+
},
|
|
914
|
+
desDecode: function (data, secretKey) {
|
|
915
|
+
if (data && secretKey) {
|
|
916
|
+
let ks = secretKey.split(',');
|
|
917
|
+
if (ks.length >= 3) {
|
|
918
|
+
return strDec(data, ks[0], ks[1], ks[2]);
|
|
919
|
+
}
|
|
920
|
+
return strDec(data, secretKey, '', '');
|
|
921
|
+
}
|
|
922
|
+
return '';
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
};
|
|
926
|
+
|
|
927
|
+
module.exports = crypto;
|