uview-pro 0.0.13 → 0.0.15

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 (234) hide show
  1. package/changelog.md +236 -217
  2. package/components/u-action-sheet/types.ts +35 -35
  3. package/components/u-action-sheet/u-action-sheet.vue +160 -160
  4. package/components/u-alert-tips/types.ts +39 -39
  5. package/components/u-alert-tips/u-alert-tips.vue +212 -212
  6. package/components/u-avatar/types.ts +34 -34
  7. package/components/u-avatar/u-avatar.vue +193 -193
  8. package/components/u-avatar-cropper/types.ts +23 -23
  9. package/components/u-avatar-cropper/u-avatar-cropper.vue +286 -286
  10. package/components/u-avatar-cropper/weCropper.d.ts +62 -62
  11. package/components/u-avatar-cropper/weCropper.js +1253 -1253
  12. package/components/u-avatar-cropper/weCropper.ts +1255 -1255
  13. package/components/u-back-top/types.ts +39 -39
  14. package/components/u-back-top/u-back-top.vue +125 -125
  15. package/components/u-badge/types.ts +36 -36
  16. package/components/u-badge/u-badge.vue +165 -165
  17. package/components/u-button/types.ts +66 -66
  18. package/components/u-button/u-button.vue +554 -554
  19. package/components/u-calendar/types.ts +63 -63
  20. package/components/u-calendar/u-calendar.vue +592 -592
  21. package/components/u-car-keyboard/types.ts +12 -12
  22. package/components/u-car-keyboard/u-car-keyboard.vue +234 -234
  23. package/components/u-card/types.ts +59 -59
  24. package/components/u-card/u-card.vue +194 -194
  25. package/components/u-cell-group/types.ts +17 -17
  26. package/components/u-cell-group/u-cell-group.vue +50 -50
  27. package/components/u-cell-item/types.ts +54 -54
  28. package/components/u-cell-item/u-cell-item.vue +202 -202
  29. package/components/u-checkbox/types.ts +31 -31
  30. package/components/u-checkbox/u-checkbox.vue +265 -265
  31. package/components/u-checkbox-group/types.ts +32 -32
  32. package/components/u-checkbox-group/u-checkbox-group.vue +79 -79
  33. package/components/u-circle-progress/types.ts +52 -52
  34. package/components/u-circle-progress/u-circle-progress.vue +189 -189
  35. package/components/u-city-select/types.ts +20 -20
  36. package/components/u-city-select/u-city-select.vue +236 -236
  37. package/components/u-col/types.ts +30 -30
  38. package/components/u-col/u-col.vue +123 -123
  39. package/components/u-collapse/types.ts +31 -31
  40. package/components/u-collapse/u-collapse.vue +68 -68
  41. package/components/u-collapse-item/types.ts +25 -25
  42. package/components/u-collapse-item/u-collapse-item.vue +176 -176
  43. package/components/u-column-notice/types.ts +48 -48
  44. package/components/u-column-notice/u-column-notice.vue +176 -176
  45. package/components/u-count-down/types.ts +42 -42
  46. package/components/u-count-down/u-count-down.vue +258 -258
  47. package/components/u-count-to/types.ts +32 -32
  48. package/components/u-count-to/u-count-to.vue +241 -241
  49. package/components/u-divider/types.ts +31 -31
  50. package/components/u-divider/u-divider.vue +121 -121
  51. package/components/u-dropdown/types.ts +32 -32
  52. package/components/u-dropdown/u-dropdown.vue +289 -289
  53. package/components/u-dropdown-item/types.ts +27 -27
  54. package/components/u-dropdown-item/u-dropdown-item.vue +123 -123
  55. package/components/u-empty/types.ts +36 -36
  56. package/components/u-empty/u-empty.vue +88 -88
  57. package/components/u-field/types.ts +69 -69
  58. package/components/u-field/u-field.vue +354 -354
  59. package/components/u-form/types.ts +6 -4
  60. package/components/u-form/u-form.vue +19 -5
  61. package/components/u-form-item/types.ts +2 -2
  62. package/components/u-form-item/u-form-item.vue +7 -6
  63. package/components/u-full-screen/types.ts +14 -14
  64. package/components/u-full-screen/u-full-screen.vue +82 -82
  65. package/components/u-gap/types.ts +18 -18
  66. package/components/u-gap/u-gap.vue +40 -40
  67. package/components/u-grid/types.ts +19 -19
  68. package/components/u-grid/u-grid.vue +93 -93
  69. package/components/u-grid-item/types.ts +16 -16
  70. package/components/u-grid-item/u-grid-item.vue +130 -130
  71. package/components/u-icon/types.ts +62 -62
  72. package/components/u-icon/u-icon.vue +274 -274
  73. package/components/u-image/types.ts +51 -49
  74. package/components/u-image/u-image.vue +222 -218
  75. package/components/u-index-anchor/types.ts +16 -16
  76. package/components/u-index-anchor/u-index-anchor.vue +86 -86
  77. package/components/u-index-list/types.ts +43 -43
  78. package/components/u-index-list/u-index-list.vue +355 -355
  79. package/components/u-input/types.ts +140 -140
  80. package/components/u-input/u-input.vue +255 -255
  81. package/components/u-keyboard/types.ts +40 -40
  82. package/components/u-keyboard/u-keyboard.vue +158 -158
  83. package/components/u-lazy-load/types.ts +37 -37
  84. package/components/u-lazy-load/u-lazy-load.vue +233 -233
  85. package/components/u-line/types.ts +44 -44
  86. package/components/u-line/u-line.vue +59 -59
  87. package/components/u-line-progress/types.ts +58 -58
  88. package/components/u-line-progress/u-line-progress.vue +109 -109
  89. package/components/u-link/types.ts +43 -43
  90. package/components/u-link/u-link.vue +75 -75
  91. package/components/u-loading/types.ts +35 -35
  92. package/components/u-loading/u-loading.vue +90 -90
  93. package/components/u-loadmore/types.ts +79 -79
  94. package/components/u-loadmore/u-loadmore.vue +140 -140
  95. package/components/u-mask/types.ts +43 -43
  96. package/components/u-mask/u-mask.vue +106 -106
  97. package/components/u-message-input/types.ts +74 -74
  98. package/components/u-message-input/u-message-input.vue +255 -255
  99. package/components/u-modal/types.ts +118 -118
  100. package/components/u-modal/u-modal.vue +200 -200
  101. package/components/u-navbar/types.ts +103 -103
  102. package/components/u-navbar/u-navbar.vue +226 -226
  103. package/components/u-no-network/image.ts +2 -2
  104. package/components/u-no-network/types.ts +28 -28
  105. package/components/u-no-network/u-no-network.vue +290 -290
  106. package/components/u-notice-bar/types.ts +111 -111
  107. package/components/u-notice-bar/u-notice-bar.vue +174 -174
  108. package/components/u-number-box/types.ts +42 -42
  109. package/components/u-number-box/u-number-box.vue +312 -312
  110. package/components/u-number-keyboard/types.ts +26 -26
  111. package/components/u-number-keyboard/u-number-keyboard.vue +166 -166
  112. package/components/u-picker/types.ts +111 -111
  113. package/components/u-picker/u-picker.vue +637 -637
  114. package/components/u-popup/types.ts +59 -59
  115. package/components/u-popup/u-popup.vue +359 -359
  116. package/components/u-radio/types.ts +25 -25
  117. package/components/u-radio/u-radio.vue +258 -258
  118. package/components/u-radio-group/types.ts +29 -29
  119. package/components/u-radio-group/u-radio-group.vue +98 -98
  120. package/components/u-rate/types.ts +40 -40
  121. package/components/u-rate/u-rate.vue +234 -234
  122. package/components/u-read-more/types.ts +35 -35
  123. package/components/u-read-more/u-read-more.vue +150 -150
  124. package/components/u-row/types.ts +20 -20
  125. package/components/u-row/u-row.vue +87 -87
  126. package/components/u-row-notice/types.ts +39 -39
  127. package/components/u-row-notice/u-row-notice.vue +213 -213
  128. package/components/u-search/types.ts +53 -53
  129. package/components/u-search/u-search.vue +256 -256
  130. package/components/u-section/types.ts +32 -32
  131. package/components/u-section/u-section.vue +125 -125
  132. package/components/u-select/types.ts +43 -43
  133. package/components/u-select/u-select.vue +361 -345
  134. package/components/u-skeleton/types.ts +20 -20
  135. package/components/u-skeleton/u-skeleton.vue +205 -205
  136. package/components/u-slider/types.ts +32 -32
  137. package/components/u-slider/u-slider.vue +238 -238
  138. package/components/u-steps/types.ts +28 -28
  139. package/components/u-steps/u-steps.vue +160 -160
  140. package/components/u-sticky/types.ts +22 -22
  141. package/components/u-sticky/u-sticky.vue +159 -159
  142. package/components/u-subsection/types.ts +36 -36
  143. package/components/u-subsection/u-subsection.vue +328 -328
  144. package/components/u-swipe-action/types.ts +50 -50
  145. package/components/u-swipe-action/u-swipe-action.vue +253 -252
  146. package/components/u-swiper/types.ts +47 -47
  147. package/components/u-swiper/u-swiper.vue +266 -266
  148. package/components/u-switch/types.ts +28 -28
  149. package/components/u-switch/u-switch.vue +128 -128
  150. package/components/u-tabbar/types.ts +36 -36
  151. package/components/u-tabbar/u-tabbar.vue +280 -280
  152. package/components/u-table/types.ts +25 -25
  153. package/components/u-table/u-table.vue +55 -55
  154. package/components/u-tabs/types.ts +51 -51
  155. package/components/u-tabs/u-tabs.vue +284 -284
  156. package/components/u-tabs-swiper/types.ts +53 -53
  157. package/components/u-tabs-swiper/u-tabs-swiper.vue +379 -379
  158. package/components/u-tag/types.ts +37 -37
  159. package/components/u-tag/u-tag.vue +244 -244
  160. package/components/u-td/types.ts +12 -12
  161. package/components/u-td/u-td.vue +69 -69
  162. package/components/u-th/types.ts +12 -12
  163. package/components/u-th/u-th.vue +63 -63
  164. package/components/u-time-line/u-time-line.vue +39 -39
  165. package/components/u-time-line-item/types.ts +14 -14
  166. package/components/u-time-line-item/u-time-line-item.vue +78 -78
  167. package/components/u-toast/types.ts +36 -36
  168. package/components/u-toast/u-toast.vue +233 -233
  169. package/components/u-top-tips/types.ts +14 -14
  170. package/components/u-top-tips/u-top-tips.vue +113 -113
  171. package/components/u-tr/types.ts +8 -8
  172. package/components/u-tr/u-tr.vue +24 -24
  173. package/components/u-upload/types.ts +71 -71
  174. package/components/u-upload/u-upload.vue +545 -545
  175. package/components/u-verification-code/types.ts +22 -22
  176. package/components/u-verification-code/u-verification-code.vue +164 -164
  177. package/components/u-waterfall/types.ts +16 -16
  178. package/components/u-waterfall/u-waterfall.vue +170 -170
  179. package/iconfont.css +910 -910
  180. package/index.scss +22 -22
  181. package/index.ts +202 -202
  182. package/libs/config/config.ts +26 -26
  183. package/libs/config/zIndex.ts +37 -37
  184. package/libs/css/color.scss +155 -155
  185. package/libs/css/common.scss +175 -175
  186. package/libs/css/style.components.scss +6 -6
  187. package/libs/css/style.h5.scss +8 -8
  188. package/libs/css/style.mp.scss +72 -72
  189. package/libs/css/style.nvue.scss +2 -2
  190. package/libs/css/style.vue.scss +175 -175
  191. package/libs/function/$parent.ts +22 -22
  192. package/libs/function/addUnit.ts +13 -13
  193. package/libs/function/color.ts +36 -36
  194. package/libs/function/colorGradient.ts +125 -125
  195. package/libs/function/debounce.ts +28 -28
  196. package/libs/function/deepClone.ts +39 -39
  197. package/libs/function/deepMerge.ts +34 -34
  198. package/libs/function/getParent.ts +58 -58
  199. package/libs/function/getRect.ts +26 -26
  200. package/libs/function/guid.ts +42 -42
  201. package/libs/function/md5.ts +398 -398
  202. package/libs/function/parent.ts +21 -21
  203. package/libs/function/queryParams.ts +60 -60
  204. package/libs/function/random.ts +16 -16
  205. package/libs/function/randomArray.ts +11 -11
  206. package/libs/function/route.ts +118 -118
  207. package/libs/function/sys.ts +15 -15
  208. package/libs/function/test.ts +229 -229
  209. package/libs/function/throttle.ts +31 -31
  210. package/libs/function/timeFormat.ts +54 -54
  211. package/libs/function/timeFrom.ts +48 -48
  212. package/libs/function/toast.ts +14 -14
  213. package/libs/function/trim.ts +21 -21
  214. package/libs/function/type2icon.ts +36 -36
  215. package/libs/hooks/useEmitter.ts +77 -77
  216. package/libs/hooks/useParent.ts +29 -29
  217. package/libs/request/auto-http.ts +76 -76
  218. package/libs/request/index.ts +237 -237
  219. package/libs/request/uni-http.md +156 -156
  220. package/libs/request/uni-http.ts +434 -434
  221. package/libs/store/index.ts +88 -88
  222. package/libs/util/async-validator.d.ts +62 -62
  223. package/libs/util/async-validator.js +1356 -1356
  224. package/libs/util/emitter.ts +112 -112
  225. package/libs/util/mitt.ts +118 -118
  226. package/libs/util/parent.ts +20 -20
  227. package/package.json +107 -107
  228. package/readme.md +231 -236
  229. package/theme.scss +38 -38
  230. package/types/components.d.ts +94 -94
  231. package/types/global.d.ts +221 -208
  232. package/types/ignore-errors.d.ts +30 -30
  233. package/types/index.d.ts +90 -90
  234. package/types/uni-app.d.ts +63 -63
@@ -1,399 +1,399 @@
1
- /*
2
- * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
3
- * Digest Algorithm, as defined in RFC 1321.
4
- * Version 2.2 Copyright (C) Paul Johnston 1999 - 2009
5
- * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
6
- * Distributed under the BSD License
7
- * See http://pajhome.org.uk/crypt/md5 for more info.
8
- */
9
-
10
- /*
11
- * Configurable variables. You may need to tweak these to be compatible with
12
- * the server-side, but the defaults work in most cases.
13
- */
14
- let hexcase: number = 0; /* hex output format. 0 - lowercase; 1 - uppercase */
15
- let b64pad: string = ""; /* base-64 pad character. "=" for strict RFC compliance */
16
-
17
- /**
18
- * 这些是通常需要调用的函数
19
- * @param s 输入字符串
20
- * @returns 十六进制/BASE64/任意编码的MD5字符串
21
- */
22
- function hex_md5(s: string): string { return rstr2hex(rstr_md5(str2rstr_utf8(s))); }
23
- function b64_md5(s: string): string { return rstr2b64(rstr_md5(str2rstr_utf8(s))); }
24
- function any_md5(s: string, e: string): string { return rstr2any(rstr_md5(str2rstr_utf8(s)), e); }
25
- function hex_hmac_md5(k: string, d: string): string {
26
- return rstr2hex(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d)));
27
- }
28
- function b64_hmac_md5(k: string, d: string): string {
29
- return rstr2b64(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d)));
30
- }
31
- function any_hmac_md5(k: string, d: string, e: string): string {
32
- return rstr2any(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d)), e);
33
- }
34
-
35
- /**
36
- * 执行简单自测,判断 VM 是否正常
37
- * @returns 是否通过测试
38
- */
39
- function md5_vm_test(): boolean {
40
- return hex_md5("abc").toLowerCase() == "900150983cd24fb0d6963f7d28e17f72";
41
- }
42
-
43
- /**
44
- * 计算原始字符串的 MD5
45
- * @param s 原始字符串
46
- * @returns MD5 结果字符串
47
- */
48
- function rstr_md5(s: string): string {
49
- return binl2rstr(binl_md5(rstr2binl(s), s.length * 8));
50
- }
51
-
52
- /**
53
- * 计算 HMAC-MD5
54
- * @param key 密钥
55
- * @param data 数据
56
- * @returns HMAC-MD5 结果字符串
57
- */
58
- function rstr_hmac_md5(key: string, data: string): string {
59
- let bkey: number[] = rstr2binl(key);
60
- if(bkey.length > 16) bkey = binl_md5(bkey, key.length * 8);
61
-
62
- const ipad: number[] = Array(16), opad: number[] = Array(16);
63
- for(let i = 0; i < 16; i++) {
64
- ipad[i] = bkey[i] ^ 0x36363636;
65
- opad[i] = bkey[i] ^ 0x5C5C5C5C;
66
- }
67
-
68
- const hash: number[] = binl_md5(ipad.concat(rstr2binl(data)), 512 + data.length * 8);
69
- return binl2rstr(binl_md5(opad.concat(hash), 512 + 128));
70
- }
71
-
72
- /**
73
- * 原始字符串转十六进制字符串
74
- * @param input 输入字符串
75
- * @returns 十六进制字符串
76
- */
77
- function rstr2hex(input: string): string {
78
- try { hexcase } catch(e) { hexcase=0; }
79
- const hex_tab: string = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
80
- let output = "";
81
- let x: number;
82
- for(let i = 0; i < input.length; i++) {
83
- x = input.charCodeAt(i);
84
- output += hex_tab.charAt((x >>> 4) & 0x0F)
85
- + hex_tab.charAt( x & 0x0F);
86
- }
87
- return output;
88
- }
89
-
90
- /**
91
- * 原始字符串转 BASE64 字符串
92
- * @param input 输入字符串
93
- * @returns BASE64 字符串
94
- */
95
- function rstr2b64(input: string): string {
96
- try { b64pad } catch(e) { b64pad=''; }
97
- const tab: string = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
98
- let output = "";
99
- const len: number = input.length;
100
- for(let i = 0; i < len; i += 3) {
101
- const triplet: number = (input.charCodeAt(i) << 16)
102
- | (i + 1 < len ? input.charCodeAt(i+1) << 8 : 0)
103
- | (i + 2 < len ? input.charCodeAt(i+2) : 0);
104
- for(let j = 0; j < 4; j++) {
105
- if(i * 8 + j * 6 > input.length * 8) output += b64pad;
106
- else output += tab.charAt((triplet >>> 6*(3-j)) & 0x3F);
107
- }
108
- }
109
- return output;
110
- }
111
-
112
- /**
113
- * 原始字符串转任意编码字符串
114
- * @param input 输入字符串
115
- * @param encoding 编码表
116
- * @returns 编码后的字符串
117
- */
118
- function rstr2any(input: string, encoding: string): string {
119
- const divisor: number = encoding.length;
120
- let i: number, j: number, q: number, x: number, quotient: number[];
121
-
122
- /* Convert to an array of 16-bit big-endian values, forming the dividend */
123
- let dividend: number[] = Array(Math.ceil(input.length / 2));
124
- for(i = 0; i < dividend.length; i++) {
125
- dividend[i] = (input.charCodeAt(i * 2) << 8) | input.charCodeAt(i * 2 + 1);
126
- }
127
-
128
- /*
129
- * Repeatedly perform a long division. The binary array forms the dividend,
130
- * the length of the encoding is the divisor. Once computed, the quotient
131
- * forms the dividend for the next step. All remainders are stored for later
132
- * use.
133
- */
134
- const full_length: number = Math.ceil(input.length * 8 /
135
- (Math.log(encoding.length) / Math.log(2)));
136
- const remainders: number[] = Array(full_length);
137
- for(j = 0; j < full_length; j++) {
138
- quotient = [];
139
- x = 0;
140
- for(i = 0; i < dividend.length; i++) {
141
- x = (x << 16) + dividend[i];
142
- q = Math.floor(x / divisor);
143
- x -= q * divisor;
144
- if(quotient.length > 0 || q > 0)
145
- quotient[quotient.length] = q;
146
- }
147
- remainders[j] = x;
148
- dividend = quotient;
149
- }
150
-
151
- /* Convert the remainders to the output string */
152
- let output = "";
153
- for(i = remainders.length - 1; i >= 0; i--)
154
- output += encoding.charAt(remainders[i]);
155
-
156
- return output;
157
- }
158
-
159
- /**
160
- * 字符串转 UTF-8 编码
161
- * @param input 输入字符串
162
- * @returns UTF-8 编码字符串
163
- */
164
- function str2rstr_utf8(input: string): string {
165
- let output = "";
166
- let i = -1;
167
- let x: number, y: number;
168
-
169
- while(++i < input.length) {
170
- /* Decode utf-16 surrogate pairs */
171
- x = input.charCodeAt(i);
172
- y = i + 1 < input.length ? input.charCodeAt(i + 1) : 0;
173
- if(0xD800 <= x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF) {
174
- x = 0x10000 + ((x & 0x03FF) << 10) + (y & 0x03FF);
175
- i++;
176
- }
177
-
178
- /* Encode output as utf-8 */
179
- if(x <= 0x7F)
180
- output += String.fromCharCode(x);
181
- else if(x <= 0x7FF)
182
- output += String.fromCharCode(0xC0 | ((x >>> 6 ) & 0x1F),
183
- 0x80 | ( x & 0x3F));
184
- else if(x <= 0xFFFF)
185
- output += String.fromCharCode(0xE0 | ((x >>> 12) & 0x0F),
186
- 0x80 | ((x >>> 6 ) & 0x3F),
187
- 0x80 | ( x & 0x3F));
188
- else if(x <= 0x1FFFFF)
189
- output += String.fromCharCode(0xF0 | ((x >>> 18) & 0x07),
190
- 0x80 | ((x >>> 12) & 0x3F),
191
- 0x80 | ((x >>> 6 ) & 0x3F),
192
- 0x80 | ( x & 0x3F));
193
- }
194
- return output;
195
- }
196
-
197
- /**
198
- * 字符串转 UTF-16LE 编码
199
- * @param input 输入字符串
200
- * @returns UTF-16LE 编码字符串
201
- */
202
- function str2rstr_utf16le(input: string): string {
203
- let output = "";
204
- for(let i = 0; i < input.length; i++)
205
- output += String.fromCharCode( input.charCodeAt(i) & 0xFF,
206
- (input.charCodeAt(i) >>> 8) & 0xFF);
207
- return output;
208
- }
209
-
210
- /**
211
- * 字符串转 UTF-16BE 编码
212
- * @param input 输入字符串
213
- * @returns UTF-16BE 编码字符串
214
- */
215
- function str2rstr_utf16be(input: string): string {
216
- let output = "";
217
- for(let i = 0; i < input.length; i++)
218
- output += String.fromCharCode((input.charCodeAt(i) >>> 8) & 0xFF,
219
- input.charCodeAt(i) & 0xFF);
220
- return output;
221
- }
222
-
223
- /**
224
- * 原始字符串转小端字数组
225
- * @param input 输入字符串
226
- * @returns 小端字数组
227
- */
228
- function rstr2binl(input: string): number[] {
229
- const output: number[] = Array(input.length >> 2);
230
- for(let i = 0; i < output.length; i++)
231
- output[i] = 0;
232
- for(let i = 0; i < input.length * 8; i += 8)
233
- output[i>>5] |= (input.charCodeAt(i / 8) & 0xFF) << (i%32);
234
- return output;
235
- }
236
-
237
- /**
238
- * 小端字数组转字符串
239
- * @param input 小端字数组
240
- * @returns 字符串
241
- */
242
- function binl2rstr(input: number[]): string {
243
- let output = "";
244
- for(let i = 0; i < input.length * 32; i += 8)
245
- output += String.fromCharCode((input[i>>5] >>> (i % 32)) & 0xFF);
246
- return output;
247
- }
248
-
249
- /**
250
- * 计算小端字数组的 MD5
251
- * @param x 小端字数组
252
- * @param len 位长度
253
- * @returns MD5 结果数组
254
- */
255
- function binl_md5(x: number[], len: number): number[] {
256
- /* append padding */
257
- x[len >> 5] |= 0x80 << ((len) % 32);
258
- x[(((len + 64) >>> 9) << 4) + 14] = len;
259
-
260
- let a = 1732584193;
261
- let b = -271733879;
262
- let c = -1732584194;
263
- let d = 271733878;
264
-
265
- for(let i = 0; i < x.length; i += 16) {
266
- const olda = a;
267
- const oldb = b;
268
- const oldc = c;
269
- const oldd = d;
270
-
271
- a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
272
- d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
273
- c = md5_ff(c, d, a, b, x[i+ 2], 17, 606105819);
274
- b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
275
- a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
276
- d = md5_ff(d, a, b, c, x[i+ 5], 12, 1200080426);
277
- c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);
278
- b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);
279
- a = md5_ff(a, b, c, d, x[i+ 8], 7 , 1770035416);
280
- d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);
281
- c = md5_ff(c, d, a, b, x[i+10], 17, -42063);
282
- b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
283
- a = md5_ff(a, b, c, d, x[i+12], 7 , 1804603682);
284
- d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
285
- c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
286
- b = md5_ff(b, c, d, a, x[i+15], 22, 1236535329);
287
-
288
- a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
289
- d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
290
- c = md5_gg(c, d, a, b, x[i+11], 14, 643717713);
291
- b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
292
- a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
293
- d = md5_gg(d, a, b, c, x[i+10], 9 , 38016083);
294
- c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);
295
- b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);
296
- a = md5_gg(a, b, c, d, x[i+ 9], 5 , 568446438);
297
- d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);
298
- c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);
299
- b = md5_gg(b, c, d, a, x[i+ 8], 20, 1163531501);
300
- a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
301
- d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
302
- c = md5_gg(c, d, a, b, x[i+ 7], 14, 1735328473);
303
- b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);
304
-
305
- a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
306
- d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
307
- c = md5_hh(c, d, a, b, x[i+11], 16, 1839030562);
308
- b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
309
- a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
310
- d = md5_hh(d, a, b, c, x[i+ 4], 11, 1272893353);
311
- c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);
312
- b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
313
- a = md5_hh(a, b, c, d, x[i+13], 4 , 681279174);
314
- d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);
315
- c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);
316
- b = md5_hh(b, c, d, a, x[i+ 6], 23, 76029189);
317
- a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
318
- d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
319
- c = md5_hh(c, d, a, b, x[i+15], 16, 530742520);
320
- b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);
321
-
322
- a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
323
- d = md5_ii(d, a, b, c, x[i+ 7], 10, 1126891415);
324
- c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
325
- b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
326
- a = md5_ii(a, b, c, d, x[i+12], 6 , 1700485571);
327
- d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);
328
- c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);
329
- b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);
330
- a = md5_ii(a, b, c, d, x[i+ 8], 6 , 1873313359);
331
- d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);
332
- c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);
333
- b = md5_ii(b, c, d, a, x[i+13], 21, 1309151649);
334
- a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
335
- d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
336
- c = md5_ii(c, d, a, b, x[i+ 2], 15, 718787259);
337
- b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);
338
-
339
- a = safe_add(a, olda);
340
- b = safe_add(b, oldb);
341
- c = safe_add(c, oldc);
342
- d = safe_add(d, oldd);
343
- }
344
- return [a, b, c, d];
345
- }
346
-
347
- /**
348
- * 四种基本操作
349
- */
350
- function md5_cmn(q: number, a: number, b: number, x: number, s: number, t: number): number {
351
- return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b);
352
- }
353
- function md5_ff(a: number, b: number, c: number, d: number, x: number, s: number, t: number): number {
354
- return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
355
- }
356
- function md5_gg(a: number, b: number, c: number, d: number, x: number, s: number, t: number): number {
357
- return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
358
- }
359
- function md5_hh(a: number, b: number, c: number, d: number, x: number, s: number, t: number): number {
360
- return md5_cmn(b ^ c ^ d, a, b, x, s, t);
361
- }
362
- function md5_ii(a: number, b: number, c: number, d: number, x: number, s: number, t: number): number {
363
- return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
364
- }
365
-
366
- /**
367
- * 安全整数加法,防止溢出
368
- * @param x 整数
369
- * @param y 整数
370
- * @returns 加法结果
371
- */
372
- function safe_add(x: number, y: number): number {
373
- const lsw: number = (x & 0xFFFF) + (y & 0xFFFF);
374
- const msw: number = (x >> 16) + (y >> 16) + (lsw >> 16);
375
- return (msw << 16) | (lsw & 0xFFFF);
376
- }
377
-
378
- /**
379
- * 左移位操作
380
- * @param num 数字
381
- * @param cnt 位数
382
- * @returns 结果
383
- */
384
- function bit_rol(num: number, cnt: number): number {
385
- return (num << cnt) | (num >>> (32 - cnt));
386
- }
387
-
388
- /**
389
- * 计算字符串的 MD5 值
390
- * @param str 输入字符串
391
- * @returns MD5 十六进制字符串
392
- */
393
- function md5(str: string): string {
394
- return hex_md5(str);
395
- }
396
-
397
- export default {
398
- md5,
1
+ /*
2
+ * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
3
+ * Digest Algorithm, as defined in RFC 1321.
4
+ * Version 2.2 Copyright (C) Paul Johnston 1999 - 2009
5
+ * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
6
+ * Distributed under the BSD License
7
+ * See http://pajhome.org.uk/crypt/md5 for more info.
8
+ */
9
+
10
+ /*
11
+ * Configurable variables. You may need to tweak these to be compatible with
12
+ * the server-side, but the defaults work in most cases.
13
+ */
14
+ let hexcase: number = 0; /* hex output format. 0 - lowercase; 1 - uppercase */
15
+ let b64pad: string = ""; /* base-64 pad character. "=" for strict RFC compliance */
16
+
17
+ /**
18
+ * 这些是通常需要调用的函数
19
+ * @param s 输入字符串
20
+ * @returns 十六进制/BASE64/任意编码的MD5字符串
21
+ */
22
+ function hex_md5(s: string): string { return rstr2hex(rstr_md5(str2rstr_utf8(s))); }
23
+ function b64_md5(s: string): string { return rstr2b64(rstr_md5(str2rstr_utf8(s))); }
24
+ function any_md5(s: string, e: string): string { return rstr2any(rstr_md5(str2rstr_utf8(s)), e); }
25
+ function hex_hmac_md5(k: string, d: string): string {
26
+ return rstr2hex(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d)));
27
+ }
28
+ function b64_hmac_md5(k: string, d: string): string {
29
+ return rstr2b64(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d)));
30
+ }
31
+ function any_hmac_md5(k: string, d: string, e: string): string {
32
+ return rstr2any(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d)), e);
33
+ }
34
+
35
+ /**
36
+ * 执行简单自测,判断 VM 是否正常
37
+ * @returns 是否通过测试
38
+ */
39
+ function md5_vm_test(): boolean {
40
+ return hex_md5("abc").toLowerCase() == "900150983cd24fb0d6963f7d28e17f72";
41
+ }
42
+
43
+ /**
44
+ * 计算原始字符串的 MD5
45
+ * @param s 原始字符串
46
+ * @returns MD5 结果字符串
47
+ */
48
+ function rstr_md5(s: string): string {
49
+ return binl2rstr(binl_md5(rstr2binl(s), s.length * 8));
50
+ }
51
+
52
+ /**
53
+ * 计算 HMAC-MD5
54
+ * @param key 密钥
55
+ * @param data 数据
56
+ * @returns HMAC-MD5 结果字符串
57
+ */
58
+ function rstr_hmac_md5(key: string, data: string): string {
59
+ let bkey: number[] = rstr2binl(key);
60
+ if(bkey.length > 16) bkey = binl_md5(bkey, key.length * 8);
61
+
62
+ const ipad: number[] = Array(16), opad: number[] = Array(16);
63
+ for(let i = 0; i < 16; i++) {
64
+ ipad[i] = bkey[i] ^ 0x36363636;
65
+ opad[i] = bkey[i] ^ 0x5C5C5C5C;
66
+ }
67
+
68
+ const hash: number[] = binl_md5(ipad.concat(rstr2binl(data)), 512 + data.length * 8);
69
+ return binl2rstr(binl_md5(opad.concat(hash), 512 + 128));
70
+ }
71
+
72
+ /**
73
+ * 原始字符串转十六进制字符串
74
+ * @param input 输入字符串
75
+ * @returns 十六进制字符串
76
+ */
77
+ function rstr2hex(input: string): string {
78
+ try { hexcase } catch(e) { hexcase=0; }
79
+ const hex_tab: string = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
80
+ let output = "";
81
+ let x: number;
82
+ for(let i = 0; i < input.length; i++) {
83
+ x = input.charCodeAt(i);
84
+ output += hex_tab.charAt((x >>> 4) & 0x0F)
85
+ + hex_tab.charAt( x & 0x0F);
86
+ }
87
+ return output;
88
+ }
89
+
90
+ /**
91
+ * 原始字符串转 BASE64 字符串
92
+ * @param input 输入字符串
93
+ * @returns BASE64 字符串
94
+ */
95
+ function rstr2b64(input: string): string {
96
+ try { b64pad } catch(e) { b64pad=''; }
97
+ const tab: string = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
98
+ let output = "";
99
+ const len: number = input.length;
100
+ for(let i = 0; i < len; i += 3) {
101
+ const triplet: number = (input.charCodeAt(i) << 16)
102
+ | (i + 1 < len ? input.charCodeAt(i+1) << 8 : 0)
103
+ | (i + 2 < len ? input.charCodeAt(i+2) : 0);
104
+ for(let j = 0; j < 4; j++) {
105
+ if(i * 8 + j * 6 > input.length * 8) output += b64pad;
106
+ else output += tab.charAt((triplet >>> 6*(3-j)) & 0x3F);
107
+ }
108
+ }
109
+ return output;
110
+ }
111
+
112
+ /**
113
+ * 原始字符串转任意编码字符串
114
+ * @param input 输入字符串
115
+ * @param encoding 编码表
116
+ * @returns 编码后的字符串
117
+ */
118
+ function rstr2any(input: string, encoding: string): string {
119
+ const divisor: number = encoding.length;
120
+ let i: number, j: number, q: number, x: number, quotient: number[];
121
+
122
+ /* Convert to an array of 16-bit big-endian values, forming the dividend */
123
+ let dividend: number[] = Array(Math.ceil(input.length / 2));
124
+ for(i = 0; i < dividend.length; i++) {
125
+ dividend[i] = (input.charCodeAt(i * 2) << 8) | input.charCodeAt(i * 2 + 1);
126
+ }
127
+
128
+ /*
129
+ * Repeatedly perform a long division. The binary array forms the dividend,
130
+ * the length of the encoding is the divisor. Once computed, the quotient
131
+ * forms the dividend for the next step. All remainders are stored for later
132
+ * use.
133
+ */
134
+ const full_length: number = Math.ceil(input.length * 8 /
135
+ (Math.log(encoding.length) / Math.log(2)));
136
+ const remainders: number[] = Array(full_length);
137
+ for(j = 0; j < full_length; j++) {
138
+ quotient = [];
139
+ x = 0;
140
+ for(i = 0; i < dividend.length; i++) {
141
+ x = (x << 16) + dividend[i];
142
+ q = Math.floor(x / divisor);
143
+ x -= q * divisor;
144
+ if(quotient.length > 0 || q > 0)
145
+ quotient[quotient.length] = q;
146
+ }
147
+ remainders[j] = x;
148
+ dividend = quotient;
149
+ }
150
+
151
+ /* Convert the remainders to the output string */
152
+ let output = "";
153
+ for(i = remainders.length - 1; i >= 0; i--)
154
+ output += encoding.charAt(remainders[i]);
155
+
156
+ return output;
157
+ }
158
+
159
+ /**
160
+ * 字符串转 UTF-8 编码
161
+ * @param input 输入字符串
162
+ * @returns UTF-8 编码字符串
163
+ */
164
+ function str2rstr_utf8(input: string): string {
165
+ let output = "";
166
+ let i = -1;
167
+ let x: number, y: number;
168
+
169
+ while(++i < input.length) {
170
+ /* Decode utf-16 surrogate pairs */
171
+ x = input.charCodeAt(i);
172
+ y = i + 1 < input.length ? input.charCodeAt(i + 1) : 0;
173
+ if(0xD800 <= x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF) {
174
+ x = 0x10000 + ((x & 0x03FF) << 10) + (y & 0x03FF);
175
+ i++;
176
+ }
177
+
178
+ /* Encode output as utf-8 */
179
+ if(x <= 0x7F)
180
+ output += String.fromCharCode(x);
181
+ else if(x <= 0x7FF)
182
+ output += String.fromCharCode(0xC0 | ((x >>> 6 ) & 0x1F),
183
+ 0x80 | ( x & 0x3F));
184
+ else if(x <= 0xFFFF)
185
+ output += String.fromCharCode(0xE0 | ((x >>> 12) & 0x0F),
186
+ 0x80 | ((x >>> 6 ) & 0x3F),
187
+ 0x80 | ( x & 0x3F));
188
+ else if(x <= 0x1FFFFF)
189
+ output += String.fromCharCode(0xF0 | ((x >>> 18) & 0x07),
190
+ 0x80 | ((x >>> 12) & 0x3F),
191
+ 0x80 | ((x >>> 6 ) & 0x3F),
192
+ 0x80 | ( x & 0x3F));
193
+ }
194
+ return output;
195
+ }
196
+
197
+ /**
198
+ * 字符串转 UTF-16LE 编码
199
+ * @param input 输入字符串
200
+ * @returns UTF-16LE 编码字符串
201
+ */
202
+ function str2rstr_utf16le(input: string): string {
203
+ let output = "";
204
+ for(let i = 0; i < input.length; i++)
205
+ output += String.fromCharCode( input.charCodeAt(i) & 0xFF,
206
+ (input.charCodeAt(i) >>> 8) & 0xFF);
207
+ return output;
208
+ }
209
+
210
+ /**
211
+ * 字符串转 UTF-16BE 编码
212
+ * @param input 输入字符串
213
+ * @returns UTF-16BE 编码字符串
214
+ */
215
+ function str2rstr_utf16be(input: string): string {
216
+ let output = "";
217
+ for(let i = 0; i < input.length; i++)
218
+ output += String.fromCharCode((input.charCodeAt(i) >>> 8) & 0xFF,
219
+ input.charCodeAt(i) & 0xFF);
220
+ return output;
221
+ }
222
+
223
+ /**
224
+ * 原始字符串转小端字数组
225
+ * @param input 输入字符串
226
+ * @returns 小端字数组
227
+ */
228
+ function rstr2binl(input: string): number[] {
229
+ const output: number[] = Array(input.length >> 2);
230
+ for(let i = 0; i < output.length; i++)
231
+ output[i] = 0;
232
+ for(let i = 0; i < input.length * 8; i += 8)
233
+ output[i>>5] |= (input.charCodeAt(i / 8) & 0xFF) << (i%32);
234
+ return output;
235
+ }
236
+
237
+ /**
238
+ * 小端字数组转字符串
239
+ * @param input 小端字数组
240
+ * @returns 字符串
241
+ */
242
+ function binl2rstr(input: number[]): string {
243
+ let output = "";
244
+ for(let i = 0; i < input.length * 32; i += 8)
245
+ output += String.fromCharCode((input[i>>5] >>> (i % 32)) & 0xFF);
246
+ return output;
247
+ }
248
+
249
+ /**
250
+ * 计算小端字数组的 MD5
251
+ * @param x 小端字数组
252
+ * @param len 位长度
253
+ * @returns MD5 结果数组
254
+ */
255
+ function binl_md5(x: number[], len: number): number[] {
256
+ /* append padding */
257
+ x[len >> 5] |= 0x80 << ((len) % 32);
258
+ x[(((len + 64) >>> 9) << 4) + 14] = len;
259
+
260
+ let a = 1732584193;
261
+ let b = -271733879;
262
+ let c = -1732584194;
263
+ let d = 271733878;
264
+
265
+ for(let i = 0; i < x.length; i += 16) {
266
+ const olda = a;
267
+ const oldb = b;
268
+ const oldc = c;
269
+ const oldd = d;
270
+
271
+ a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
272
+ d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
273
+ c = md5_ff(c, d, a, b, x[i+ 2], 17, 606105819);
274
+ b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
275
+ a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
276
+ d = md5_ff(d, a, b, c, x[i+ 5], 12, 1200080426);
277
+ c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);
278
+ b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);
279
+ a = md5_ff(a, b, c, d, x[i+ 8], 7 , 1770035416);
280
+ d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);
281
+ c = md5_ff(c, d, a, b, x[i+10], 17, -42063);
282
+ b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
283
+ a = md5_ff(a, b, c, d, x[i+12], 7 , 1804603682);
284
+ d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
285
+ c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
286
+ b = md5_ff(b, c, d, a, x[i+15], 22, 1236535329);
287
+
288
+ a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
289
+ d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
290
+ c = md5_gg(c, d, a, b, x[i+11], 14, 643717713);
291
+ b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
292
+ a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
293
+ d = md5_gg(d, a, b, c, x[i+10], 9 , 38016083);
294
+ c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);
295
+ b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);
296
+ a = md5_gg(a, b, c, d, x[i+ 9], 5 , 568446438);
297
+ d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);
298
+ c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);
299
+ b = md5_gg(b, c, d, a, x[i+ 8], 20, 1163531501);
300
+ a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
301
+ d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
302
+ c = md5_gg(c, d, a, b, x[i+ 7], 14, 1735328473);
303
+ b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);
304
+
305
+ a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
306
+ d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
307
+ c = md5_hh(c, d, a, b, x[i+11], 16, 1839030562);
308
+ b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
309
+ a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
310
+ d = md5_hh(d, a, b, c, x[i+ 4], 11, 1272893353);
311
+ c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);
312
+ b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
313
+ a = md5_hh(a, b, c, d, x[i+13], 4 , 681279174);
314
+ d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);
315
+ c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);
316
+ b = md5_hh(b, c, d, a, x[i+ 6], 23, 76029189);
317
+ a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
318
+ d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
319
+ c = md5_hh(c, d, a, b, x[i+15], 16, 530742520);
320
+ b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);
321
+
322
+ a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
323
+ d = md5_ii(d, a, b, c, x[i+ 7], 10, 1126891415);
324
+ c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
325
+ b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
326
+ a = md5_ii(a, b, c, d, x[i+12], 6 , 1700485571);
327
+ d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);
328
+ c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);
329
+ b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);
330
+ a = md5_ii(a, b, c, d, x[i+ 8], 6 , 1873313359);
331
+ d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);
332
+ c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);
333
+ b = md5_ii(b, c, d, a, x[i+13], 21, 1309151649);
334
+ a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
335
+ d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
336
+ c = md5_ii(c, d, a, b, x[i+ 2], 15, 718787259);
337
+ b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);
338
+
339
+ a = safe_add(a, olda);
340
+ b = safe_add(b, oldb);
341
+ c = safe_add(c, oldc);
342
+ d = safe_add(d, oldd);
343
+ }
344
+ return [a, b, c, d];
345
+ }
346
+
347
+ /**
348
+ * 四种基本操作
349
+ */
350
+ function md5_cmn(q: number, a: number, b: number, x: number, s: number, t: number): number {
351
+ return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b);
352
+ }
353
+ function md5_ff(a: number, b: number, c: number, d: number, x: number, s: number, t: number): number {
354
+ return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
355
+ }
356
+ function md5_gg(a: number, b: number, c: number, d: number, x: number, s: number, t: number): number {
357
+ return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
358
+ }
359
+ function md5_hh(a: number, b: number, c: number, d: number, x: number, s: number, t: number): number {
360
+ return md5_cmn(b ^ c ^ d, a, b, x, s, t);
361
+ }
362
+ function md5_ii(a: number, b: number, c: number, d: number, x: number, s: number, t: number): number {
363
+ return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
364
+ }
365
+
366
+ /**
367
+ * 安全整数加法,防止溢出
368
+ * @param x 整数
369
+ * @param y 整数
370
+ * @returns 加法结果
371
+ */
372
+ function safe_add(x: number, y: number): number {
373
+ const lsw: number = (x & 0xFFFF) + (y & 0xFFFF);
374
+ const msw: number = (x >> 16) + (y >> 16) + (lsw >> 16);
375
+ return (msw << 16) | (lsw & 0xFFFF);
376
+ }
377
+
378
+ /**
379
+ * 左移位操作
380
+ * @param num 数字
381
+ * @param cnt 位数
382
+ * @returns 结果
383
+ */
384
+ function bit_rol(num: number, cnt: number): number {
385
+ return (num << cnt) | (num >>> (32 - cnt));
386
+ }
387
+
388
+ /**
389
+ * 计算字符串的 MD5 值
390
+ * @param str 输入字符串
391
+ * @returns MD5 十六进制字符串
392
+ */
393
+ function md5(str: string): string {
394
+ return hex_md5(str);
395
+ }
396
+
397
+ export default {
398
+ md5,
399
399
  };