ddan-js 2.9.4 → 2.9.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.
Files changed (131) hide show
  1. package/bin/types/browser.d.ts +1 -1
  2. package/bin/types/index.d.ts +1 -1
  3. package/bin/types/modules/node/aliyun.d.ts +1 -1
  4. package/bin/types/upload.d.ts +2 -0
  5. package/bin/upload.js +1 -0
  6. package/package.json +18 -13
  7. package/bin/lib/browser.js +0 -111
  8. package/bin/lib/class/event.js +0 -104
  9. package/bin/lib/class/getset.js +0 -12
  10. package/bin/lib/class/icon.js +0 -94
  11. package/bin/lib/class/joker.js +0 -121
  12. package/bin/lib/class/kvalue.js +0 -29
  13. package/bin/lib/class/mapping.js +0 -82
  14. package/bin/lib/class/persist.js +0 -65
  15. package/bin/lib/class/pipeTask.js +0 -42
  16. package/bin/lib/class/pipeparallel.js +0 -24
  17. package/bin/lib/class/store.js +0 -87
  18. package/bin/lib/class/tracker.js +0 -125
  19. package/bin/lib/class/watermark.js +0 -63
  20. package/bin/lib/common/_Symbol.js +0 -5
  21. package/bin/lib/common/_freeGlobal.js +0 -5
  22. package/bin/lib/common/_object.js +0 -40
  23. package/bin/lib/common/_root.js +0 -10
  24. package/bin/lib/common/internal/asciiToArray.js +0 -13
  25. package/bin/lib/common/internal/castSlice.js +0 -18
  26. package/bin/lib/common/internal/createCaseFirst.js +0 -30
  27. package/bin/lib/common/internal/hasUnicode.js +0 -26
  28. package/bin/lib/common/internal/nodeTypes.js +0 -26
  29. package/bin/lib/common/internal/slice.js +0 -46
  30. package/bin/lib/common/internal/stringToArray.js +0 -18
  31. package/bin/lib/common/internal/unicodeToArray.js +0 -40
  32. package/bin/lib/common/internal/unicodeWords.js +0 -67
  33. package/bin/lib/index.js +0 -114
  34. package/bin/lib/modules/browser/ecdh.js +0 -124
  35. package/bin/lib/modules/browser/index.js +0 -4
  36. package/bin/lib/modules/cdn.js +0 -62
  37. package/bin/lib/modules/convert/base.js +0 -125
  38. package/bin/lib/modules/convert/base64.js +0 -114
  39. package/bin/lib/modules/convert/index.js +0 -99
  40. package/bin/lib/modules/convert/md5.js +0 -222
  41. package/bin/lib/modules/convert/pkcs.js +0 -16
  42. package/bin/lib/modules/convert/utf8.js +0 -106
  43. package/bin/lib/modules/crypto/base64.js +0 -14
  44. package/bin/lib/modules/crypto/const.js +0 -7
  45. package/bin/lib/modules/crypto/index.js +0 -30
  46. package/bin/lib/modules/crypto/rsa.js +0 -143
  47. package/bin/lib/modules/crypto/tea.js +0 -79
  48. package/bin/lib/modules/crypto/uuid.js +0 -34
  49. package/bin/lib/modules/css.js +0 -137
  50. package/bin/lib/modules/decorator.js +0 -14
  51. package/bin/lib/modules/fetch.js +0 -82
  52. package/bin/lib/modules/gbk.js +0 -46
  53. package/bin/lib/modules/hook/base.js +0 -60
  54. package/bin/lib/modules/hook/hooker.js +0 -39
  55. package/bin/lib/modules/hook/index.js +0 -49
  56. package/bin/lib/modules/hook/log.js +0 -54
  57. package/bin/lib/modules/hook/modules/bezier.js +0 -121
  58. package/bin/lib/modules/hook/modules/debounce.js +0 -127
  59. package/bin/lib/modules/hook/modules/mutex.js +0 -22
  60. package/bin/lib/modules/hook/modules/pipeline.js +0 -59
  61. package/bin/lib/modules/hook/modules/polling.js +0 -20
  62. package/bin/lib/modules/hook/modules/safeTask.js +0 -25
  63. package/bin/lib/modules/hook/modules/throttle.js +0 -30
  64. package/bin/lib/modules/html.js +0 -293
  65. package/bin/lib/modules/http/index.js +0 -171
  66. package/bin/lib/modules/http/interceptor.js +0 -22
  67. package/bin/lib/modules/list/base.js +0 -37
  68. package/bin/lib/modules/list/index.js +0 -90
  69. package/bin/lib/modules/logger.js +0 -55
  70. package/bin/lib/modules/math/index.js +0 -118
  71. package/bin/lib/modules/mini/diff.js +0 -97
  72. package/bin/lib/modules/mini/http/index.js +0 -155
  73. package/bin/lib/modules/mini/index.js +0 -71
  74. package/bin/lib/modules/node/aliyun.js +0 -156
  75. package/bin/lib/modules/node/brotli.js +0 -46
  76. package/bin/lib/modules/node/child.js +0 -18
  77. package/bin/lib/modules/node/ecdh-web.js +0 -11
  78. package/bin/lib/modules/node/ecdh.js +0 -115
  79. package/bin/lib/modules/node/file.js +0 -25
  80. package/bin/lib/modules/node/index.js +0 -11
  81. package/bin/lib/modules/node/proxy.js +0 -147
  82. package/bin/lib/modules/node/rsa-web.js +0 -19
  83. package/bin/lib/modules/node/socks5.js +0 -424
  84. package/bin/lib/modules/obj/index.js +0 -184
  85. package/bin/lib/modules/qs/base.js +0 -5
  86. package/bin/lib/modules/qs/decode.js +0 -45
  87. package/bin/lib/modules/qs/encode.js +0 -53
  88. package/bin/lib/modules/qs/index.js +0 -152
  89. package/bin/lib/modules/regex.js +0 -16
  90. package/bin/lib/modules/rsa.js +0 -18
  91. package/bin/lib/modules/rule/async-validator/index.js +0 -306
  92. package/bin/lib/modules/rule/async-validator/interface.js +0 -2
  93. package/bin/lib/modules/rule/async-validator/messages.js +0 -59
  94. package/bin/lib/modules/rule/async-validator/rule/enum.js +0 -13
  95. package/bin/lib/modules/rule/async-validator/rule/index.js +0 -16
  96. package/bin/lib/modules/rule/async-validator/rule/pattern.js +0 -27
  97. package/bin/lib/modules/rule/async-validator/rule/range.js +0 -54
  98. package/bin/lib/modules/rule/async-validator/rule/required.js +0 -12
  99. package/bin/lib/modules/rule/async-validator/rule/type.js +0 -98
  100. package/bin/lib/modules/rule/async-validator/rule/url.js +0 -55
  101. package/bin/lib/modules/rule/async-validator/rule/whitespace.js +0 -20
  102. package/bin/lib/modules/rule/async-validator/util.js +0 -255
  103. package/bin/lib/modules/rule/async-validator/validator/any.js +0 -16
  104. package/bin/lib/modules/rule/async-validator/validator/array.js +0 -19
  105. package/bin/lib/modules/rule/async-validator/validator/boolean.js +0 -20
  106. package/bin/lib/modules/rule/async-validator/validator/date.js +0 -31
  107. package/bin/lib/modules/rule/async-validator/validator/enum.js +0 -20
  108. package/bin/lib/modules/rule/async-validator/validator/float.js +0 -20
  109. package/bin/lib/modules/rule/async-validator/validator/index.js +0 -36
  110. package/bin/lib/modules/rule/async-validator/validator/integer.js +0 -20
  111. package/bin/lib/modules/rule/async-validator/validator/method.js +0 -19
  112. package/bin/lib/modules/rule/async-validator/validator/number.js +0 -23
  113. package/bin/lib/modules/rule/async-validator/validator/object.js +0 -19
  114. package/bin/lib/modules/rule/async-validator/validator/pattern.js +0 -19
  115. package/bin/lib/modules/rule/async-validator/validator/regexp.js +0 -19
  116. package/bin/lib/modules/rule/async-validator/validator/required.js +0 -10
  117. package/bin/lib/modules/rule/async-validator/validator/string.js +0 -24
  118. package/bin/lib/modules/rule/async-validator/validator/type.js +0 -20
  119. package/bin/lib/modules/rule/index.js +0 -67
  120. package/bin/lib/modules/string/index.js +0 -121
  121. package/bin/lib/modules/string/words.js +0 -33
  122. package/bin/lib/modules/time/const.js +0 -11
  123. package/bin/lib/modules/time/dtime.js +0 -132
  124. package/bin/lib/modules/time/frame.js +0 -49
  125. package/bin/lib/modules/time/index.js +0 -84
  126. package/bin/lib/typings/index.js +0 -2
  127. package/bin/lib/util/function.js +0 -33
  128. package/bin/lib/util/includes.js +0 -96
  129. package/bin/lib/util/index.js +0 -26
  130. package/bin/lib/util/is.js +0 -148
  131. package/bin/lib/util/to.js +0 -47
@@ -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
- };
@@ -1,143 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const convert_1 = require("../convert");
4
- const RSAPublicKey = `MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApiLWsPmoaiGdr02AmPYS
5
- 4/VgxyJNNJSK2VICirXl4P8qAP3b/6GIs7Hwnsmmuj7gledJ0XiZodFjDNgQEZEG
6
- j4K9KX8NixcrJwnTQV5UebiERdj+64ihwqPVWo9dIOj43ZPJ8f4dritJv5tnQaBb
7
- b9zTkU3Ofzk1g8RU00Ith6quOGZcU2IWC4OQ+5YiZvzrCBKEvjFwK2OvGq43tI51
8
- GaZdI9H09jisypqefsMvv6esjEQQOtl+WGlI5fof7KZUt3dppvuDI4CYgeXIoKKL
9
- 9T9qDl8F9aNSs3XHx32YyA7L1FraFD6PjqRjueIFp2emsXQcIMeMqqgVyV+4qb+0
10
- uwIDAQAB`;
11
- const RSAPrivateKey = `MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCmItaw+ahqIZ2v
12
- TYCY9hLj9WDHIk00lIrZUgKKteXg/yoA/dv/oYizsfCeyaa6PuCV50nReJmh0WMM
13
- 2BARkQaPgr0pfw2LFysnCdNBXlR5uIRF2P7riKHCo9Vaj10g6Pjdk8nx/h2uK0m/
14
- m2dBoFtv3NORTc5/OTWDxFTTQi2Hqq44ZlxTYhYLg5D7liJm/OsIEoS+MXArY68a
15
- rje0jnUZpl0j0fT2OKzKmp5+wy+/p6yMRBA62X5YaUjl+h/splS3d2mm+4MjgJiB
16
- 5cigoov1P2oOXwX1o1KzdcfHfZjIDsvUWtoUPo+OpGO54gWnZ6axdBwgx4yqqBXJ
17
- X7ipv7S7AgMBAAECggEAE1kuWLkSsJ2OoDpt9iJ+a7cJmNd5V1zPWOTwr9fkWFJP
18
- QYNPKlPVOFxKUivY84rcHAkuMyuQ9OQOXZISOQGDWpZW0mzeFmtR1r+Rr2S9gNmI
19
- 6huOAL9OW306HUxiA7GuPhv2omy+Zyjac2q1WVLEI2B78Um2+WEfxuNIH7xu0gRR
20
- z/wluevMBQlv6hSeMESP6e9s2kB+FuM4bL7+1sexwS1TudKbHybujaiB8un9E2V3
21
- C9BkE6yf00Rhvii6Q4E4w3PFQfcBEFnjOD0S2Watx8GIbYjlYvtquy8Yj7OtyZB6
22
- w5sxyaYhKVVnkpGAbOgaCj94ABYF47VuwXr45I4PzQKBgQDp6svzD+QKlARjcWgO
23
- rH7UEpFX6m49G6Ib4c63xEg9+GesTgfDxoYxtXDKsC7I8OwMrmffJGbyfjaAvzmg
24
- icM3Y7kF6UPO9+q2mBRsyhoJSNONTeUVyoFSc+QDsVgndlTZIjqC5XLrONGaSPLJ
25
- 7jJzqKhp3NQcpO8+xY0d7Efm1QKBgQC10fCNuF1LUTYgsWvvGxTiCCAIBurZmHU+
26
- GMb2Okfoco/P+QNl1jEba91AC7FudW3g/lRn0vTnDajlNoz2/CKunrTKN4/9lEBI
27
- tiwEOvhc5FtapRifSfrrNwFqPM+LijvOkcteWVhAUWCEP1eLmpnXGqfmZxnTaaVe
28
- 5DyDgyAVTwKBgQDhEawfOQEANJ9sV2f6BnsZ7quuXcCoR3hZP5G5O8EO735BSesq
29
- sk/YcG4QeCjr6vQU15LWH552YH5srpHyJ9uP5gHW8DTwZZaPDhFJA8S9fjcfVP3B
30
- U9HO1fdknjTl83N8YPTPkZpbPZZfzyTcqrYclwFEqtfkn8YbLdW0Hu6n6QKBgDEv
31
- jvS3uD1ExfDILlurptWSvx+Mx4F/1c+roj8/+u3t9+uaAIpPDE/PuTW3NBOens/r
32
- 3WeM0QWkU1lWjYHPKY61jlDaARDnRxCkf3nRfhibCf+Wg/erar6wzagwtTCZf55d
33
- IHfwkYgsu4BrJkK02wMuydbxczIW9U6bTaeCFG7PAoGAN3oHYzTEBwZ7ZKv11QiQ
34
- Ep/HeHBvD8fH/e1uVyBel4Co7NO5pV2s8qjS8+3+jxumKLNXCirjqwHo03YCdzxi
35
- cy4GFDsukHmDQ7FF9VC4QV0fJ0F7jGYE9nNZ+K9qwS5KrihOSBPxj0HptrF6TSOw
36
- BTSwr0byL3TC0m0StkSNKpo=`;
37
- const generateKeys = async (subtle) => {
38
- try {
39
- // 生成RSA密钥对
40
- const keyPair = await subtle.generateKey({
41
- name: 'RSA-OAEP',
42
- modulusLength: 2048,
43
- publicExponent: new Uint8Array([1, 0, 1]),
44
- hash: 'SHA-256',
45
- }, true, // 是否可导出密钥
46
- ['encrypt', 'decrypt']);
47
- // 导出公钥为SPKI格式(可共享)
48
- const publicBuffer = await window.crypto.subtle.exportKey('spki', keyPair.publicKey);
49
- const publicKey = format_pem_content(publicBuffer);
50
- const publicKeyPem = format_pem_key(publicKey, 'PUBLIC KEY');
51
- // 导出私钥为PKCS#8格式(需保护)
52
- const privateBuffer = await window.crypto.subtle.exportKey('pkcs8', keyPair.privateKey);
53
- const privateKey = format_pem_content(privateBuffer);
54
- const privateKeyPem = format_pem_key(privateKey, 'PRIVATE KEY');
55
- return {
56
- publicKey,
57
- publicKeyPem,
58
- privateKey,
59
- privateKeyPem,
60
- };
61
- }
62
- catch (err) {
63
- console.error('generateKeys failed:', err);
64
- return {
65
- publicKey: '',
66
- publicKeyPem: '',
67
- privateKey: '',
68
- privateKeyPem: '',
69
- };
70
- }
71
- };
72
- const format_pem_content = (buffer) => {
73
- try {
74
- const base64String = convert_1.default.ab2str(buffer, true);
75
- return base64String.match(/.{1,64}/g)?.join('\n') || '';
76
- }
77
- catch (error) {
78
- return '';
79
- }
80
- };
81
- const format_pem_key = (pemContent = '', label = 'PUBLIC KEY') => {
82
- return `-----BEGIN ${label}-----\n${pemContent}\n-----END ${label}-----`;
83
- };
84
- // SHA256: 256 - 2 - 2*32 = 190
85
- // SHA1: 256 - 2 - 2*20 = 214
86
- const maxChunkSize = 190;
87
- const encrypt = async (subtle, data, publicKey) => {
88
- try {
89
- const bytes = new TextEncoder().encode(data);
90
- const key = await subtle.importKey('spki', convert_1.default.str2ab(publicKey, true), {
91
- name: 'RSA-OAEP',
92
- hash: 'SHA-256',
93
- }, true, ['encrypt']);
94
- const encryptedChunks = [];
95
- for (let i = 0; i < bytes.length; i += maxChunkSize) {
96
- let chunk = bytes.slice(i, i + maxChunkSize);
97
- let encryptedChunk = await subtle.encrypt({
98
- name: 'RSA-OAEP',
99
- }, key, chunk);
100
- encryptedChunks.push(new Uint8Array(encryptedChunk));
101
- }
102
- const enctryptedBytes = convert_1.default.concatBytes(...encryptedChunks);
103
- return convert_1.default.bytesToBase64(enctryptedBytes);
104
- }
105
- catch (error) {
106
- console.error(`[debug] encrypt`, error);
107
- return '';
108
- }
109
- };
110
- const decrypt = async (subtle, encryptedBase64, privateKey) => {
111
- try {
112
- const encrypted = convert_1.default.base64ToBytes(encryptedBase64);
113
- const key = await subtle.importKey('pkcs8', convert_1.default.str2ab(privateKey, true), {
114
- name: 'RSA-OAEP',
115
- hash: 'SHA-256',
116
- }, true, ['decrypt']);
117
- const decryptedChunks = [];
118
- const chunkSize = 256; // 每个加密块的大小(2048位 RSA 的加密输出为 256 字节)
119
- for (let i = 0; i < encrypted.length; i += chunkSize) {
120
- let chunk = encrypted.slice(i, i + chunkSize);
121
- let decryptedChunk = await subtle.decrypt({
122
- name: 'RSA-OAEP',
123
- }, key, chunk);
124
- // 添加解密后的数据
125
- decryptedChunks.push(new Uint8Array(decryptedChunk));
126
- }
127
- const encryptedBytes = convert_1.default.concatBytes(...decryptedChunks);
128
- return new TextDecoder().decode(encryptedBytes);
129
- }
130
- catch (err) {
131
- console.error('decrypt failed:', err);
132
- return '';
133
- }
134
- };
135
- exports.default = {
136
- RSAPublicKey,
137
- RSAPrivateKey,
138
- generateKeys,
139
- format_pem_key,
140
- format_pem_content,
141
- encrypt,
142
- decrypt,
143
- };