ddan-js 2.9.3 → 2.9.5
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/bin/ddan-js.browser.js +1 -1
- package/bin/ddan-js.esm.js +1 -1
- package/bin/ddan-js.js +1 -1
- package/bin/types/browser.d.ts +3 -3
- package/bin/types/index.d.ts +4 -3
- package/bin/types/modules/fetch.d.ts +1 -1
- package/bin/types/modules/node/index.d.ts +2 -0
- package/package.json +18 -13
- package/bin/lib/browser.js +0 -111
- package/bin/lib/class/event.js +0 -104
- package/bin/lib/class/getset.js +0 -12
- package/bin/lib/class/icon.js +0 -94
- package/bin/lib/class/joker.js +0 -121
- package/bin/lib/class/kvalue.js +0 -29
- package/bin/lib/class/mapping.js +0 -82
- package/bin/lib/class/persist.js +0 -65
- package/bin/lib/class/pipeTask.js +0 -42
- package/bin/lib/class/pipeparallel.js +0 -24
- package/bin/lib/class/store.js +0 -87
- package/bin/lib/class/tracker.js +0 -125
- package/bin/lib/class/watermark.js +0 -63
- package/bin/lib/common/_Symbol.js +0 -5
- package/bin/lib/common/_freeGlobal.js +0 -5
- package/bin/lib/common/_object.js +0 -40
- package/bin/lib/common/_root.js +0 -10
- package/bin/lib/common/internal/asciiToArray.js +0 -13
- package/bin/lib/common/internal/castSlice.js +0 -18
- package/bin/lib/common/internal/createCaseFirst.js +0 -30
- package/bin/lib/common/internal/hasUnicode.js +0 -26
- package/bin/lib/common/internal/nodeTypes.js +0 -26
- package/bin/lib/common/internal/slice.js +0 -46
- package/bin/lib/common/internal/stringToArray.js +0 -18
- package/bin/lib/common/internal/unicodeToArray.js +0 -40
- package/bin/lib/common/internal/unicodeWords.js +0 -67
- package/bin/lib/index.js +0 -114
- package/bin/lib/modules/browser/ecdh.js +0 -124
- package/bin/lib/modules/browser/index.js +0 -4
- package/bin/lib/modules/cdn.js +0 -62
- package/bin/lib/modules/convert/base.js +0 -125
- package/bin/lib/modules/convert/base64.js +0 -114
- package/bin/lib/modules/convert/index.js +0 -99
- package/bin/lib/modules/convert/md5.js +0 -222
- package/bin/lib/modules/convert/pkcs.js +0 -16
- package/bin/lib/modules/convert/utf8.js +0 -106
- package/bin/lib/modules/crypto/base64.js +0 -14
- package/bin/lib/modules/crypto/const.js +0 -7
- package/bin/lib/modules/crypto/index.js +0 -30
- package/bin/lib/modules/crypto/rsa.js +0 -143
- package/bin/lib/modules/crypto/tea.js +0 -79
- package/bin/lib/modules/crypto/uuid.js +0 -34
- package/bin/lib/modules/css.js +0 -137
- package/bin/lib/modules/decorator.js +0 -14
- package/bin/lib/modules/fetch.js +0 -82
- package/bin/lib/modules/gbk.js +0 -46
- package/bin/lib/modules/hook/base.js +0 -60
- package/bin/lib/modules/hook/hooker.js +0 -39
- package/bin/lib/modules/hook/index.js +0 -49
- package/bin/lib/modules/hook/log.js +0 -54
- package/bin/lib/modules/hook/modules/bezier.js +0 -121
- package/bin/lib/modules/hook/modules/debounce.js +0 -127
- package/bin/lib/modules/hook/modules/mutex.js +0 -22
- package/bin/lib/modules/hook/modules/pipeline.js +0 -59
- package/bin/lib/modules/hook/modules/polling.js +0 -20
- package/bin/lib/modules/hook/modules/safeTask.js +0 -25
- package/bin/lib/modules/hook/modules/throttle.js +0 -30
- package/bin/lib/modules/html.js +0 -293
- package/bin/lib/modules/http/index.js +0 -171
- package/bin/lib/modules/http/interceptor.js +0 -22
- package/bin/lib/modules/list/base.js +0 -37
- package/bin/lib/modules/list/index.js +0 -90
- package/bin/lib/modules/logger.js +0 -55
- package/bin/lib/modules/math/index.js +0 -118
- package/bin/lib/modules/mini/diff.js +0 -97
- package/bin/lib/modules/mini/http/index.js +0 -155
- package/bin/lib/modules/mini/index.js +0 -71
- package/bin/lib/modules/node/aliyun.js +0 -156
- package/bin/lib/modules/node/brotli.js +0 -46
- package/bin/lib/modules/node/child.js +0 -18
- package/bin/lib/modules/node/ecdh-web.js +0 -11
- package/bin/lib/modules/node/ecdh.js +0 -115
- package/bin/lib/modules/node/file.js +0 -25
- package/bin/lib/modules/node/index.js +0 -11
- package/bin/lib/modules/node/proxy.js +0 -147
- package/bin/lib/modules/node/rsa-web.js +0 -19
- package/bin/lib/modules/node/socks5.js +0 -424
- package/bin/lib/modules/obj/index.js +0 -184
- package/bin/lib/modules/qs/base.js +0 -5
- package/bin/lib/modules/qs/decode.js +0 -45
- package/bin/lib/modules/qs/encode.js +0 -53
- package/bin/lib/modules/qs/index.js +0 -114
- package/bin/lib/modules/regex.js +0 -16
- package/bin/lib/modules/rsa.js +0 -18
- package/bin/lib/modules/rule/async-validator/index.js +0 -306
- package/bin/lib/modules/rule/async-validator/interface.js +0 -2
- package/bin/lib/modules/rule/async-validator/messages.js +0 -59
- package/bin/lib/modules/rule/async-validator/rule/enum.js +0 -13
- package/bin/lib/modules/rule/async-validator/rule/index.js +0 -16
- package/bin/lib/modules/rule/async-validator/rule/pattern.js +0 -27
- package/bin/lib/modules/rule/async-validator/rule/range.js +0 -54
- package/bin/lib/modules/rule/async-validator/rule/required.js +0 -12
- package/bin/lib/modules/rule/async-validator/rule/type.js +0 -98
- package/bin/lib/modules/rule/async-validator/rule/url.js +0 -55
- package/bin/lib/modules/rule/async-validator/rule/whitespace.js +0 -20
- package/bin/lib/modules/rule/async-validator/util.js +0 -255
- package/bin/lib/modules/rule/async-validator/validator/any.js +0 -16
- package/bin/lib/modules/rule/async-validator/validator/array.js +0 -19
- package/bin/lib/modules/rule/async-validator/validator/boolean.js +0 -20
- package/bin/lib/modules/rule/async-validator/validator/date.js +0 -31
- package/bin/lib/modules/rule/async-validator/validator/enum.js +0 -20
- package/bin/lib/modules/rule/async-validator/validator/float.js +0 -20
- package/bin/lib/modules/rule/async-validator/validator/index.js +0 -36
- package/bin/lib/modules/rule/async-validator/validator/integer.js +0 -20
- package/bin/lib/modules/rule/async-validator/validator/method.js +0 -19
- package/bin/lib/modules/rule/async-validator/validator/number.js +0 -23
- package/bin/lib/modules/rule/async-validator/validator/object.js +0 -19
- package/bin/lib/modules/rule/async-validator/validator/pattern.js +0 -19
- package/bin/lib/modules/rule/async-validator/validator/regexp.js +0 -19
- package/bin/lib/modules/rule/async-validator/validator/required.js +0 -10
- package/bin/lib/modules/rule/async-validator/validator/string.js +0 -24
- package/bin/lib/modules/rule/async-validator/validator/type.js +0 -20
- package/bin/lib/modules/rule/index.js +0 -67
- package/bin/lib/modules/string/index.js +0 -121
- package/bin/lib/modules/string/words.js +0 -33
- package/bin/lib/modules/time/const.js +0 -11
- package/bin/lib/modules/time/dtime.js +0 -132
- package/bin/lib/modules/time/frame.js +0 -49
- package/bin/lib/modules/time/index.js +0 -84
- package/bin/lib/typings/index.js +0 -2
- package/bin/lib/util/function.js +0 -33
- package/bin/lib/util/includes.js +0 -96
- package/bin/lib/util/index.js +0 -26
- package/bin/lib/util/is.js +0 -148
- package/bin/lib/util/to.js +0 -47
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const utf8_1 = require("./utf8");
|
|
4
|
-
const is_1 = require("../../util/is");
|
|
5
|
-
const BaseKey = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
|
6
|
-
const bytesToBase64 = (bytes) => {
|
|
7
|
-
let output = '';
|
|
8
|
-
let chr1, chr2, chr3, enc1, enc2, enc3, enc4;
|
|
9
|
-
let i = 0;
|
|
10
|
-
if (!bytes || !is_1.default.isArrayLike(bytes) || !is_1.default.isUint8Array(bytes))
|
|
11
|
-
return '';
|
|
12
|
-
while (i < bytes.length) {
|
|
13
|
-
chr1 = bytes[i++];
|
|
14
|
-
chr2 = bytes[i++];
|
|
15
|
-
chr3 = bytes[i++];
|
|
16
|
-
enc1 = chr1 >> 2;
|
|
17
|
-
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
|
|
18
|
-
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
|
|
19
|
-
enc4 = chr3 & 63;
|
|
20
|
-
if (isNaN(chr2)) {
|
|
21
|
-
enc3 = enc4 = 64;
|
|
22
|
-
}
|
|
23
|
-
else if (isNaN(chr3)) {
|
|
24
|
-
enc4 = 64;
|
|
25
|
-
}
|
|
26
|
-
output =
|
|
27
|
-
output +
|
|
28
|
-
BaseKey.charAt(enc1) +
|
|
29
|
-
BaseKey.charAt(enc2) +
|
|
30
|
-
BaseKey.charAt(enc3) +
|
|
31
|
-
BaseKey.charAt(enc4);
|
|
32
|
-
}
|
|
33
|
-
return output;
|
|
34
|
-
};
|
|
35
|
-
const toBase64 = (input = "") => {
|
|
36
|
-
let output = '';
|
|
37
|
-
let chr1, chr2, chr3, enc1, enc2, enc3, enc4;
|
|
38
|
-
let i = 0;
|
|
39
|
-
input = utf8_1.default.toUtf8(input);
|
|
40
|
-
while (i < input.length) {
|
|
41
|
-
chr1 = input.charCodeAt(i++);
|
|
42
|
-
chr2 = input.charCodeAt(i++);
|
|
43
|
-
chr3 = input.charCodeAt(i++);
|
|
44
|
-
enc1 = chr1 >> 2;
|
|
45
|
-
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
|
|
46
|
-
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
|
|
47
|
-
enc4 = chr3 & 63;
|
|
48
|
-
if (isNaN(chr2)) {
|
|
49
|
-
enc3 = enc4 = 64;
|
|
50
|
-
}
|
|
51
|
-
else if (isNaN(chr3)) {
|
|
52
|
-
enc4 = 64;
|
|
53
|
-
}
|
|
54
|
-
output =
|
|
55
|
-
output +
|
|
56
|
-
BaseKey.charAt(enc1) +
|
|
57
|
-
BaseKey.charAt(enc2) +
|
|
58
|
-
BaseKey.charAt(enc3) +
|
|
59
|
-
BaseKey.charAt(enc4);
|
|
60
|
-
}
|
|
61
|
-
return output;
|
|
62
|
-
};
|
|
63
|
-
const base64ToBytes = (input = "") => {
|
|
64
|
-
let output = [];
|
|
65
|
-
let chr1, chr2, chr3;
|
|
66
|
-
let enc1, enc2, enc3, enc4;
|
|
67
|
-
let i = 0;
|
|
68
|
-
// Remove any characters that are not valid Base64
|
|
69
|
-
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, '');
|
|
70
|
-
while (i < input.length) {
|
|
71
|
-
enc1 = BaseKey.indexOf(input.charAt(i++));
|
|
72
|
-
enc2 = BaseKey.indexOf(input.charAt(i++));
|
|
73
|
-
enc3 = BaseKey.indexOf(input.charAt(i++));
|
|
74
|
-
enc4 = BaseKey.indexOf(input.charAt(i++));
|
|
75
|
-
chr1 = (enc1 << 2) | (enc2 >> 4);
|
|
76
|
-
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
|
|
77
|
-
chr3 = ((enc3 & 3) << 6) | enc4;
|
|
78
|
-
output.push(chr1);
|
|
79
|
-
if (enc3 != 64) {
|
|
80
|
-
output.push(chr2);
|
|
81
|
-
}
|
|
82
|
-
if (enc4 != 64) {
|
|
83
|
-
output.push(chr3);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
// Convert the array to Uint8Array and return
|
|
87
|
-
return new Uint8Array(output);
|
|
88
|
-
};
|
|
89
|
-
const fromBase64 = (input = "") => {
|
|
90
|
-
let output = '';
|
|
91
|
-
let chr1, chr2, chr3;
|
|
92
|
-
let enc1, enc2, enc3, enc4;
|
|
93
|
-
let i = 0;
|
|
94
|
-
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, '');
|
|
95
|
-
while (i < input.length) {
|
|
96
|
-
enc1 = BaseKey.indexOf(input.charAt(i++));
|
|
97
|
-
enc2 = BaseKey.indexOf(input.charAt(i++));
|
|
98
|
-
enc3 = BaseKey.indexOf(input.charAt(i++));
|
|
99
|
-
enc4 = BaseKey.indexOf(input.charAt(i++));
|
|
100
|
-
chr1 = (enc1 << 2) | (enc2 >> 4);
|
|
101
|
-
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
|
|
102
|
-
chr3 = ((enc3 & 3) << 6) | enc4;
|
|
103
|
-
output = output + String.fromCharCode(chr1);
|
|
104
|
-
if (enc3 != 64) {
|
|
105
|
-
output = output + String.fromCharCode(chr2);
|
|
106
|
-
}
|
|
107
|
-
if (enc4 != 64) {
|
|
108
|
-
output = output + String.fromCharCode(chr3);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
output = utf8_1.default.fromUtf8(output);
|
|
112
|
-
return output;
|
|
113
|
-
};
|
|
114
|
-
exports.default = { toBase64, fromBase64, bytesToBase64, base64ToBytes };
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const base64_1 = require("./base64");
|
|
4
|
-
const is_1 = require("../../util/is");
|
|
5
|
-
const utf8_1 = require("./utf8");
|
|
6
|
-
const math_1 = require("../math");
|
|
7
|
-
const base_1 = require("./base");
|
|
8
|
-
const pkcs_1 = require("./pkcs");
|
|
9
|
-
const md5_1 = require("./md5");
|
|
10
|
-
const str2ab = (content = '', base64 = false) => {
|
|
11
|
-
if (base64) {
|
|
12
|
-
return base64_1.default.base64ToBytes(content).buffer;
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
const buf = new ArrayBuffer(content.length);
|
|
16
|
-
const bufView = new Uint8Array(buf);
|
|
17
|
-
for (let i = 0, strLen = content.length; i < strLen; i++) {
|
|
18
|
-
bufView[i] = content.charCodeAt(i);
|
|
19
|
-
}
|
|
20
|
-
return buf;
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
const ab2str = (data, base64 = false) => {
|
|
24
|
-
const uint8Array = new Uint8Array(data);
|
|
25
|
-
if (base64) {
|
|
26
|
-
return base64_1.default.bytesToBase64(uint8Array);
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
return uint8Array.reduce((str, byte) => str + String.fromCharCode(byte), '');
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
const utf8ToBase64 = (str) => {
|
|
33
|
-
if (is_1.default.isBrowser) {
|
|
34
|
-
return btoa(str);
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
return Buffer.from(str, 'utf-8').toString('base64');
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
const base64ToUtf8 = (base64Str) => {
|
|
41
|
-
if (is_1.default.isBrowser) {
|
|
42
|
-
return atob(base64Str);
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
return Buffer.from(base64Str, 'base64').toString('utf-8');
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
const getRandomBytes = (length) => {
|
|
49
|
-
const randomBytes = new Uint8Array(length);
|
|
50
|
-
// 使用 Math.random() 生成伪随机字节
|
|
51
|
-
for (let i = 0; i < length; i++) {
|
|
52
|
-
randomBytes[i] = math_1.default.random(256); // 生成 0-255 的随机数
|
|
53
|
-
}
|
|
54
|
-
return randomBytes;
|
|
55
|
-
};
|
|
56
|
-
/**
|
|
57
|
-
* utf-8 encode
|
|
58
|
-
* new TextEncoder().encode(data);
|
|
59
|
-
* @param text
|
|
60
|
-
* @returns
|
|
61
|
-
*/
|
|
62
|
-
const textEncode = (text) => {
|
|
63
|
-
return utf8_1.default.toUtf8Bytes(text);
|
|
64
|
-
};
|
|
65
|
-
/**
|
|
66
|
-
* utf-8 decode
|
|
67
|
-
* new TextDecoder().decode(buf)
|
|
68
|
-
* @param buf
|
|
69
|
-
* @returns
|
|
70
|
-
*/
|
|
71
|
-
const textDecode = (buf) => {
|
|
72
|
-
return utf8_1.default.fromUtf8Bytes(new Uint8Array(buf));
|
|
73
|
-
};
|
|
74
|
-
const toDataUrl = (textOrBuf, contentType = 'text/plain') => {
|
|
75
|
-
if (!textOrBuf)
|
|
76
|
-
return '';
|
|
77
|
-
if (typeof textOrBuf === 'string') {
|
|
78
|
-
return `data:${contentType};base64,` + base64_1.default.toBase64(textOrBuf);
|
|
79
|
-
}
|
|
80
|
-
if (is_1.default.isArrayBuffer(textOrBuf)) {
|
|
81
|
-
return `data:${contentType};base64,` + ab2str(textOrBuf, true);
|
|
82
|
-
}
|
|
83
|
-
return '';
|
|
84
|
-
};
|
|
85
|
-
exports.default = {
|
|
86
|
-
...base_1.default,
|
|
87
|
-
...pkcs_1.default,
|
|
88
|
-
...utf8_1.default,
|
|
89
|
-
...base64_1.default,
|
|
90
|
-
...md5_1.default,
|
|
91
|
-
str2ab,
|
|
92
|
-
ab2str,
|
|
93
|
-
utf8ToBase64,
|
|
94
|
-
base64ToUtf8,
|
|
95
|
-
getRandomBytes,
|
|
96
|
-
textEncode,
|
|
97
|
-
textDecode,
|
|
98
|
-
toDataUrl,
|
|
99
|
-
};
|
|
@@ -1,222 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const utf8_1 = require("./utf8");
|
|
4
|
-
const base_1 = require("./base");
|
|
5
|
-
const base64_1 = require("./base64");
|
|
6
|
-
function rotateLeft(lValue, iShiftBits) {
|
|
7
|
-
return (lValue << iShiftBits) | (lValue >>> (32 - iShiftBits));
|
|
8
|
-
}
|
|
9
|
-
function addUnsigned(lX, lY) {
|
|
10
|
-
let lX4;
|
|
11
|
-
let lY4;
|
|
12
|
-
let lX8;
|
|
13
|
-
let lY8;
|
|
14
|
-
let lResult;
|
|
15
|
-
lX8 = lX & 0x80000000;
|
|
16
|
-
lY8 = lY & 0x80000000;
|
|
17
|
-
lX4 = lX & 0x40000000;
|
|
18
|
-
lY4 = lY & 0x40000000;
|
|
19
|
-
lResult = (lX & 0x3fffffff) + (lY & 0x3fffffff);
|
|
20
|
-
if (lX4 & lY4) {
|
|
21
|
-
return lResult ^ 0x80000000 ^ lX8 ^ lY8;
|
|
22
|
-
}
|
|
23
|
-
if (lX4 | lY4) {
|
|
24
|
-
if (lResult & 0x40000000) {
|
|
25
|
-
return lResult ^ 0xc0000000 ^ lX8 ^ lY8;
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
return lResult ^ 0x40000000 ^ lX8 ^ lY8;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
return lResult ^ lX8 ^ lY8;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
function F(x, y, z) {
|
|
36
|
-
return (x & y) | (~x & z);
|
|
37
|
-
}
|
|
38
|
-
function G(x, y, z) {
|
|
39
|
-
return (x & z) | (y & ~z);
|
|
40
|
-
}
|
|
41
|
-
function H(x, y, z) {
|
|
42
|
-
return x ^ y ^ z;
|
|
43
|
-
}
|
|
44
|
-
function I(x, y, z) {
|
|
45
|
-
return y ^ (x | ~z);
|
|
46
|
-
}
|
|
47
|
-
function FF(a, b, c, d, x, s, ac) {
|
|
48
|
-
a = addUnsigned(a, addUnsigned(addUnsigned(F(b, c, d), x), ac));
|
|
49
|
-
return addUnsigned(rotateLeft(a, s), b);
|
|
50
|
-
}
|
|
51
|
-
function GG(a, b, c, d, x, s, ac) {
|
|
52
|
-
a = addUnsigned(a, addUnsigned(addUnsigned(G(b, c, d), x), ac));
|
|
53
|
-
return addUnsigned(rotateLeft(a, s), b);
|
|
54
|
-
}
|
|
55
|
-
function HH(a, b, c, d, x, s, ac) {
|
|
56
|
-
a = addUnsigned(a, addUnsigned(addUnsigned(H(b, c, d), x), ac));
|
|
57
|
-
return addUnsigned(rotateLeft(a, s), b);
|
|
58
|
-
}
|
|
59
|
-
function II(a, b, c, d, x, s, ac) {
|
|
60
|
-
a = addUnsigned(a, addUnsigned(addUnsigned(I(b, c, d), x), ac));
|
|
61
|
-
return addUnsigned(rotateLeft(a, s), b);
|
|
62
|
-
}
|
|
63
|
-
function convertToWordArray(data) {
|
|
64
|
-
let lWordCount;
|
|
65
|
-
const lMessageLength = data.length;
|
|
66
|
-
const lNumberOfWordsTemp1 = lMessageLength + 8;
|
|
67
|
-
const lNumberOfWordsTemp2 = (lNumberOfWordsTemp1 - (lNumberOfWordsTemp1 % 64)) / 64;
|
|
68
|
-
const lNumberOfWords = (lNumberOfWordsTemp2 + 1) * 16;
|
|
69
|
-
const lWordArray = Array(lNumberOfWords - 1).fill(0);
|
|
70
|
-
let lBytePosition = 0;
|
|
71
|
-
let lByteCount = 0;
|
|
72
|
-
// Process each byte from the Uint8Array
|
|
73
|
-
while (lByteCount < lMessageLength) {
|
|
74
|
-
lWordCount = (lByteCount - (lByteCount % 4)) / 4;
|
|
75
|
-
lBytePosition = (lByteCount % 4) * 8;
|
|
76
|
-
lWordArray[lWordCount] = lWordArray[lWordCount] | (data[lByteCount] << lBytePosition);
|
|
77
|
-
lByteCount++;
|
|
78
|
-
}
|
|
79
|
-
// Append padding bits
|
|
80
|
-
lWordCount = (lByteCount - (lByteCount % 4)) / 4;
|
|
81
|
-
lBytePosition = (lByteCount % 4) * 8;
|
|
82
|
-
lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80 << lBytePosition);
|
|
83
|
-
// Append message length in bits
|
|
84
|
-
lWordArray[lNumberOfWords - 2] = lMessageLength << 3;
|
|
85
|
-
lWordArray[lNumberOfWords - 1] = lMessageLength >>> 29;
|
|
86
|
-
return lWordArray;
|
|
87
|
-
}
|
|
88
|
-
function wordToHex(lValue) {
|
|
89
|
-
let wordToHexValue = '';
|
|
90
|
-
let wordToHexValueTemp = '';
|
|
91
|
-
let lByte;
|
|
92
|
-
let lCount;
|
|
93
|
-
for (lCount = 0; lCount <= 3; lCount++) {
|
|
94
|
-
lByte = (lValue >>> (lCount * 8)) & 255;
|
|
95
|
-
wordToHexValueTemp = '0' + lByte.toString(16);
|
|
96
|
-
wordToHexValue = wordToHexValue + wordToHexValueTemp.substr(wordToHexValueTemp.length - 2, 2);
|
|
97
|
-
}
|
|
98
|
-
return wordToHexValue;
|
|
99
|
-
}
|
|
100
|
-
function hash(bytes) {
|
|
101
|
-
let x = [];
|
|
102
|
-
let k;
|
|
103
|
-
let AA;
|
|
104
|
-
let BB;
|
|
105
|
-
let CC;
|
|
106
|
-
let DD;
|
|
107
|
-
let a;
|
|
108
|
-
let b;
|
|
109
|
-
let c;
|
|
110
|
-
let d;
|
|
111
|
-
const S11 = 7;
|
|
112
|
-
const S12 = 12;
|
|
113
|
-
const S13 = 17;
|
|
114
|
-
const S14 = 22;
|
|
115
|
-
const S21 = 5;
|
|
116
|
-
const S22 = 9;
|
|
117
|
-
const S23 = 14;
|
|
118
|
-
const S24 = 20;
|
|
119
|
-
const S31 = 4;
|
|
120
|
-
const S32 = 11;
|
|
121
|
-
const S33 = 16;
|
|
122
|
-
const S34 = 23;
|
|
123
|
-
const S41 = 6;
|
|
124
|
-
const S42 = 10;
|
|
125
|
-
const S43 = 15;
|
|
126
|
-
const S44 = 21;
|
|
127
|
-
x = convertToWordArray(bytes);
|
|
128
|
-
a = 0x67452301;
|
|
129
|
-
b = 0xefcdab89;
|
|
130
|
-
c = 0x98badcfe;
|
|
131
|
-
d = 0x10325476;
|
|
132
|
-
for (k = 0; k < x.length; k += 16) {
|
|
133
|
-
AA = a;
|
|
134
|
-
BB = b;
|
|
135
|
-
CC = c;
|
|
136
|
-
DD = d;
|
|
137
|
-
a = FF(a, b, c, d, x[k + 0], S11, 0xd76aa478);
|
|
138
|
-
d = FF(d, a, b, c, x[k + 1], S12, 0xe8c7b756);
|
|
139
|
-
c = FF(c, d, a, b, x[k + 2], S13, 0x242070db);
|
|
140
|
-
b = FF(b, c, d, a, x[k + 3], S14, 0xc1bdceee);
|
|
141
|
-
a = FF(a, b, c, d, x[k + 4], S11, 0xf57c0faf);
|
|
142
|
-
d = FF(d, a, b, c, x[k + 5], S12, 0x4787c62a);
|
|
143
|
-
c = FF(c, d, a, b, x[k + 6], S13, 0xa8304613);
|
|
144
|
-
b = FF(b, c, d, a, x[k + 7], S14, 0xfd469501);
|
|
145
|
-
a = FF(a, b, c, d, x[k + 8], S11, 0x698098d8);
|
|
146
|
-
d = FF(d, a, b, c, x[k + 9], S12, 0x8b44f7af);
|
|
147
|
-
c = FF(c, d, a, b, x[k + 10], S13, 0xffff5bb1);
|
|
148
|
-
b = FF(b, c, d, a, x[k + 11], S14, 0x895cd7be);
|
|
149
|
-
a = FF(a, b, c, d, x[k + 12], S11, 0x6b901122);
|
|
150
|
-
d = FF(d, a, b, c, x[k + 13], S12, 0xfd987193);
|
|
151
|
-
c = FF(c, d, a, b, x[k + 14], S13, 0xa679438e);
|
|
152
|
-
b = FF(b, c, d, a, x[k + 15], S14, 0x49b40821);
|
|
153
|
-
a = GG(a, b, c, d, x[k + 1], S21, 0xf61e2562);
|
|
154
|
-
d = GG(d, a, b, c, x[k + 6], S22, 0xc040b340);
|
|
155
|
-
c = GG(c, d, a, b, x[k + 11], S23, 0x265e5a51);
|
|
156
|
-
b = GG(b, c, d, a, x[k + 0], S24, 0xe9b6c7aa);
|
|
157
|
-
a = GG(a, b, c, d, x[k + 5], S21, 0xd62f105d);
|
|
158
|
-
d = GG(d, a, b, c, x[k + 10], S22, 0x2441453);
|
|
159
|
-
c = GG(c, d, a, b, x[k + 15], S23, 0xd8a1e681);
|
|
160
|
-
b = GG(b, c, d, a, x[k + 4], S24, 0xe7d3fbc8);
|
|
161
|
-
a = GG(a, b, c, d, x[k + 9], S21, 0x21e1cde6);
|
|
162
|
-
d = GG(d, a, b, c, x[k + 14], S22, 0xc33707d6);
|
|
163
|
-
c = GG(c, d, a, b, x[k + 3], S23, 0xf4d50d87);
|
|
164
|
-
b = GG(b, c, d, a, x[k + 8], S24, 0x455a14ed);
|
|
165
|
-
a = GG(a, b, c, d, x[k + 13], S21, 0xa9e3e905);
|
|
166
|
-
d = GG(d, a, b, c, x[k + 2], S22, 0xfcefa3f8);
|
|
167
|
-
c = GG(c, d, a, b, x[k + 7], S23, 0x676f02d9);
|
|
168
|
-
b = GG(b, c, d, a, x[k + 12], S24, 0x8d2a4c8a);
|
|
169
|
-
a = HH(a, b, c, d, x[k + 5], S31, 0xfffa3942);
|
|
170
|
-
d = HH(d, a, b, c, x[k + 8], S32, 0x8771f681);
|
|
171
|
-
c = HH(c, d, a, b, x[k + 11], S33, 0x6d9d6122);
|
|
172
|
-
b = HH(b, c, d, a, x[k + 14], S34, 0xfde5380c);
|
|
173
|
-
a = HH(a, b, c, d, x[k + 1], S31, 0xa4beea44);
|
|
174
|
-
d = HH(d, a, b, c, x[k + 4], S32, 0x4bdecfa9);
|
|
175
|
-
c = HH(c, d, a, b, x[k + 7], S33, 0xf6bb4b60);
|
|
176
|
-
b = HH(b, c, d, a, x[k + 10], S34, 0xbebfbc70);
|
|
177
|
-
a = HH(a, b, c, d, x[k + 13], S31, 0x289b7ec6);
|
|
178
|
-
d = HH(d, a, b, c, x[k + 0], S32, 0xeaa127fa);
|
|
179
|
-
c = HH(c, d, a, b, x[k + 3], S33, 0xd4ef3085);
|
|
180
|
-
b = HH(b, c, d, a, x[k + 6], S34, 0x4881d05);
|
|
181
|
-
a = HH(a, b, c, d, x[k + 9], S31, 0xd9d4d039);
|
|
182
|
-
d = HH(d, a, b, c, x[k + 12], S32, 0xe6db99e5);
|
|
183
|
-
c = HH(c, d, a, b, x[k + 15], S33, 0x1fa27cf8);
|
|
184
|
-
b = HH(b, c, d, a, x[k + 2], S34, 0xc4ac5665);
|
|
185
|
-
a = II(a, b, c, d, x[k + 0], S41, 0xf4292244);
|
|
186
|
-
d = II(d, a, b, c, x[k + 7], S42, 0x432aff97);
|
|
187
|
-
c = II(c, d, a, b, x[k + 14], S43, 0xab9423a7);
|
|
188
|
-
b = II(b, c, d, a, x[k + 5], S44, 0xfc93a039);
|
|
189
|
-
a = II(a, b, c, d, x[k + 12], S41, 0x655b59c3);
|
|
190
|
-
d = II(d, a, b, c, x[k + 3], S42, 0x8f0ccc92);
|
|
191
|
-
c = II(c, d, a, b, x[k + 10], S43, 0xffeff47d);
|
|
192
|
-
b = II(b, c, d, a, x[k + 1], S44, 0x85845dd1);
|
|
193
|
-
a = II(a, b, c, d, x[k + 8], S41, 0x6fa87e4f);
|
|
194
|
-
d = II(d, a, b, c, x[k + 15], S42, 0xfe2ce6e0);
|
|
195
|
-
c = II(c, d, a, b, x[k + 6], S43, 0xa3014314);
|
|
196
|
-
b = II(b, c, d, a, x[k + 13], S44, 0x4e0811a1);
|
|
197
|
-
a = II(a, b, c, d, x[k + 4], S41, 0xf7537e82);
|
|
198
|
-
d = II(d, a, b, c, x[k + 11], S42, 0xbd3af235);
|
|
199
|
-
c = II(c, d, a, b, x[k + 2], S43, 0x2ad7d2bb);
|
|
200
|
-
b = II(b, c, d, a, x[k + 9], S44, 0xeb86d391);
|
|
201
|
-
a = addUnsigned(a, AA);
|
|
202
|
-
b = addUnsigned(b, BB);
|
|
203
|
-
c = addUnsigned(c, CC);
|
|
204
|
-
d = addUnsigned(d, DD);
|
|
205
|
-
}
|
|
206
|
-
return wordToHex(a) + wordToHex(b) + wordToHex(c) + wordToHex(d);
|
|
207
|
-
}
|
|
208
|
-
const md5 = (input) => {
|
|
209
|
-
if (typeof input !== 'string' && !(input instanceof Uint8Array)) {
|
|
210
|
-
return '';
|
|
211
|
-
}
|
|
212
|
-
const bytes = typeof input === 'string' ? utf8_1.default.toUtf8Bytes(input) : input;
|
|
213
|
-
return hash(bytes);
|
|
214
|
-
};
|
|
215
|
-
const md5Base64 = (input) => {
|
|
216
|
-
const hex = md5(input);
|
|
217
|
-
if (!hex)
|
|
218
|
-
return '';
|
|
219
|
-
const bytes = base_1.default.hex2bytes(hex);
|
|
220
|
-
return base64_1.default.bytesToBase64(bytes);
|
|
221
|
-
};
|
|
222
|
-
exports.default = { md5, md5Base64 };
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const base_1 = require("./base");
|
|
4
|
-
// PKCS#7 填充函数,将明文填充到指定的块大小(8 字节)
|
|
5
|
-
const pkcs7Padding = (plaintext, blockSize) => {
|
|
6
|
-
const padding = blockSize - (plaintext.length % blockSize);
|
|
7
|
-
const padtext = new Uint8Array(padding).fill(padding);
|
|
8
|
-
const result = base_1.default.concatBytes(plaintext, padtext);
|
|
9
|
-
return result;
|
|
10
|
-
};
|
|
11
|
-
// PKCS#7 去除填充函数,解密后去掉填充字符
|
|
12
|
-
const pkcs7Unpadding = (ciphertext) => {
|
|
13
|
-
const padding = ciphertext[ciphertext.length - 1];
|
|
14
|
-
return ciphertext.slice(0, -padding);
|
|
15
|
-
};
|
|
16
|
-
exports.default = { pkcs7Padding, pkcs7Unpadding };
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const toUtf8 = (content) => {
|
|
4
|
-
if (!content)
|
|
5
|
-
return '';
|
|
6
|
-
const string = content.replace(/\r\n/g, '\n');
|
|
7
|
-
let utftext = '';
|
|
8
|
-
for (let n = 0; n < string.length; n++) {
|
|
9
|
-
let c = string.charCodeAt(n);
|
|
10
|
-
if (c < 128) {
|
|
11
|
-
utftext += String.fromCharCode(c);
|
|
12
|
-
}
|
|
13
|
-
else if (c > 127 && c < 2048) {
|
|
14
|
-
utftext += String.fromCharCode((c >> 6) | 192);
|
|
15
|
-
utftext += String.fromCharCode((c & 63) | 128);
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
utftext += String.fromCharCode((c >> 12) | 224);
|
|
19
|
-
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
|
|
20
|
-
utftext += String.fromCharCode((c & 63) | 128);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return utftext;
|
|
24
|
-
};
|
|
25
|
-
const toUtf8Bytes = (content) => {
|
|
26
|
-
if (!content)
|
|
27
|
-
return new Uint8Array();
|
|
28
|
-
const string = content.replace(/\r\n/g, '\n');
|
|
29
|
-
const utf8 = [];
|
|
30
|
-
for (let n = 0; n < string.length; n++) {
|
|
31
|
-
let c = string.charCodeAt(n);
|
|
32
|
-
if (c < 128) {
|
|
33
|
-
utf8.push(c);
|
|
34
|
-
}
|
|
35
|
-
else if (c < 2048) {
|
|
36
|
-
utf8.push((c >> 6) | 192);
|
|
37
|
-
utf8.push((c & 63) | 128);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
utf8.push((c >> 12) | 224);
|
|
41
|
-
utf8.push(((c >> 6) & 63) | 128);
|
|
42
|
-
utf8.push((c & 63) | 128);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return new Uint8Array(utf8);
|
|
46
|
-
};
|
|
47
|
-
const fromUtf8 = (utftext) => {
|
|
48
|
-
let result = '';
|
|
49
|
-
let i = 0;
|
|
50
|
-
if (!utftext)
|
|
51
|
-
return '';
|
|
52
|
-
let c = 0, c1 = 0, c2 = 0, c3 = 0;
|
|
53
|
-
while (i < utftext.length) {
|
|
54
|
-
c = utftext.charCodeAt(i);
|
|
55
|
-
if (c < 128) {
|
|
56
|
-
result += String.fromCharCode(c);
|
|
57
|
-
i++;
|
|
58
|
-
}
|
|
59
|
-
else if (c > 191 && c < 224) {
|
|
60
|
-
c2 = utftext.charCodeAt(i + 1);
|
|
61
|
-
result += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
|
|
62
|
-
i += 2;
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
c2 = utftext.charCodeAt(i + 1);
|
|
66
|
-
c3 = utftext.charCodeAt(i + 2);
|
|
67
|
-
result += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
|
|
68
|
-
i += 3;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return result;
|
|
72
|
-
};
|
|
73
|
-
const fromUtf8Bytes = (utf8Bytes) => {
|
|
74
|
-
let result = '';
|
|
75
|
-
let i = 0;
|
|
76
|
-
if (!utf8Bytes || utf8Bytes.length <= 0)
|
|
77
|
-
return '';
|
|
78
|
-
while (i < utf8Bytes.length) {
|
|
79
|
-
let c = utf8Bytes[i];
|
|
80
|
-
// 单字节字符 (ASCII)
|
|
81
|
-
if (c < 128) {
|
|
82
|
-
result += String.fromCharCode(c);
|
|
83
|
-
i++;
|
|
84
|
-
}
|
|
85
|
-
// 双字节字符
|
|
86
|
-
else if (c > 191 && c < 224) {
|
|
87
|
-
const c2 = utf8Bytes[i + 1];
|
|
88
|
-
result += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
|
|
89
|
-
i += 2;
|
|
90
|
-
}
|
|
91
|
-
// 三字节字符
|
|
92
|
-
else {
|
|
93
|
-
const c2 = utf8Bytes[i + 1];
|
|
94
|
-
const c3 = utf8Bytes[i + 2];
|
|
95
|
-
result += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
|
|
96
|
-
i += 3;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return result;
|
|
100
|
-
};
|
|
101
|
-
exports.default = {
|
|
102
|
-
toUtf8,
|
|
103
|
-
fromUtf8,
|
|
104
|
-
toUtf8Bytes,
|
|
105
|
-
fromUtf8Bytes
|
|
106
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const base64_1 = require("../convert/base64");
|
|
4
|
-
const encode = (input) => {
|
|
5
|
-
return base64_1.default.toBase64(input);
|
|
6
|
-
};
|
|
7
|
-
const encodeByOss = (input) => {
|
|
8
|
-
// base64编码并部分替换
|
|
9
|
-
return encode(input).replace(/\+/g, '-').replace(/\//g, '_').replace(/\=/g, '');
|
|
10
|
-
};
|
|
11
|
-
const decode = (base64Str) => {
|
|
12
|
-
return base64_1.default.fromBase64(base64Str);
|
|
13
|
-
};
|
|
14
|
-
exports.default = { encode, decode, encodeByOss };
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const keyNumber = "0123456789";
|
|
4
|
-
const keyLower = "abcdefghijklmnopqrstuvwxyz";
|
|
5
|
-
const keyUpper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
6
|
-
const keyChars = keyNumber + keyLower + keyUpper;
|
|
7
|
-
exports.default = { keyNumber, keyLower, keyUpper, keyChars };
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const time_1 = require("../time");
|
|
4
|
-
const base64_1 = require("./base64");
|
|
5
|
-
const const_1 = require("./const");
|
|
6
|
-
const uuid_1 = require("./uuid");
|
|
7
|
-
const tea_1 = require("./tea");
|
|
8
|
-
const guid = (len, prefix = false, sep = "") => {
|
|
9
|
-
const pwd = (0, uuid_1.default)(len || 32);
|
|
10
|
-
if (!prefix)
|
|
11
|
-
return pwd;
|
|
12
|
-
return time_1.default.now().format("yyyyMMddhhmmss") + sep + pwd;
|
|
13
|
-
};
|
|
14
|
-
const getHexString = (len) => {
|
|
15
|
-
const characters = const_1.default.keyChars;
|
|
16
|
-
let result = '';
|
|
17
|
-
const charactersLength = characters.length;
|
|
18
|
-
for (let i = 0; i < len; i++) {
|
|
19
|
-
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
20
|
-
}
|
|
21
|
-
return result;
|
|
22
|
-
};
|
|
23
|
-
exports.default = {
|
|
24
|
-
...const_1.default,
|
|
25
|
-
base64: base64_1.default,
|
|
26
|
-
tea: tea_1.default,
|
|
27
|
-
uuid: uuid_1.default,
|
|
28
|
-
guid,
|
|
29
|
-
getHexString
|
|
30
|
-
};
|