@ivujs/i-utils 1.1.18 → 2.1.0

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 (142) hide show
  1. package/README.md +122 -58
  2. package/dist/cjs/ID-card/index.cjs +95 -0
  3. package/dist/cjs/array/index.cjs +476 -0
  4. package/dist/cjs/clipboard/index.cjs +132 -0
  5. package/dist/cjs/color/index.cjs +207 -0
  6. package/dist/cjs/constants/date.cjs +178 -0
  7. package/dist/cjs/constants/id-card.cjs +52 -0
  8. package/dist/cjs/constants/keycode.cjs +117 -0
  9. package/dist/cjs/constants/lang.cjs +13 -0
  10. package/dist/cjs/constants/math.cjs +13 -0
  11. package/dist/cjs/constants/regexp.cjs +53 -0
  12. package/dist/cjs/constants/sort.cjs +15 -0
  13. package/dist/cjs/cookie/index.cjs +73 -0
  14. package/dist/cjs/crypto/base64/base64.cjs +540 -0
  15. package/dist/cjs/crypto/base64/index.cjs +82 -0
  16. package/dist/cjs/crypto/md5/index.cjs +49 -0
  17. package/dist/cjs/crypto/md5/md5.cjs +351 -0
  18. package/dist/cjs/crypto/sha256/index.cjs +95 -0
  19. package/dist/cjs/crypto/sha256/sha256.cjs +557 -0
  20. package/dist/cjs/crypto/sm3/index.cjs +27 -0
  21. package/dist/cjs/crypto/sm3/sm3.cjs +200 -0
  22. package/dist/cjs/crypto/sm4/index.cjs +101 -0
  23. package/dist/cjs/crypto/sm4/sm4.cjs +498 -0
  24. package/dist/cjs/date/index.cjs +1310 -0
  25. package/dist/cjs/desensitized/index.cjs +78 -0
  26. package/dist/cjs/device/index.cjs +154 -0
  27. package/dist/cjs/dom/index.cjs +132 -0
  28. package/dist/cjs/file/index.cjs +343 -0
  29. package/dist/cjs/function/index.cjs +72 -0
  30. package/dist/cjs/id/index.cjs +6 -2
  31. package/dist/cjs/index.cjs +383 -7
  32. package/dist/cjs/keycode/index.cjs +30 -0
  33. package/dist/cjs/math/index.cjs +310 -0
  34. package/dist/cjs/number/index.cjs +34 -0
  35. package/dist/cjs/object/index.cjs +319 -0
  36. package/dist/cjs/pagination/index.cjs +146 -0
  37. package/dist/cjs/random/index.cjs +27 -0
  38. package/dist/cjs/regexp/index.cjs +103 -0
  39. package/dist/cjs/storage/index.cjs +14 -0
  40. package/dist/cjs/storage/localStorage.cjs +37 -0
  41. package/dist/cjs/storage/sessionStorage.cjs +37 -0
  42. package/dist/cjs/string/index.cjs +361 -0
  43. package/dist/cjs/url/index.cjs +261 -0
  44. package/dist/cjs/validate/index.cjs +484 -0
  45. package/dist/es/ID-card/index.d.ts +36 -0
  46. package/dist/es/ID-card/index.mjs +89 -0
  47. package/dist/es/array/index.d.ts +209 -0
  48. package/dist/es/array/index.mjs +447 -0
  49. package/dist/es/clipboard/index.d.ts +32 -0
  50. package/dist/es/clipboard/index.mjs +126 -0
  51. package/dist/es/color/index.d.ts +55 -0
  52. package/dist/es/color/index.mjs +197 -0
  53. package/dist/es/constants/date.d.ts +4 -0
  54. package/dist/es/constants/date.mjs +176 -0
  55. package/dist/es/constants/id-card.d.ts +4 -0
  56. package/dist/es/constants/id-card.mjs +50 -0
  57. package/dist/es/constants/index.d.ts +11 -0
  58. package/dist/es/constants/keycode.d.ts +1 -0
  59. package/dist/es/constants/keycode.mjs +115 -0
  60. package/dist/es/constants/lang.d.ts +4 -0
  61. package/dist/es/constants/lang.mjs +11 -0
  62. package/dist/es/constants/math.d.ts +4 -0
  63. package/dist/es/constants/math.mjs +11 -0
  64. package/dist/es/constants/regexp.d.ts +4 -0
  65. package/dist/es/constants/regexp.mjs +51 -0
  66. package/dist/es/constants/sort.d.ts +4 -0
  67. package/dist/es/constants/sort.mjs +13 -0
  68. package/dist/es/cookie/index.d.ts +29 -0
  69. package/dist/es/cookie/index.mjs +67 -0
  70. package/dist/es/crypto/base64/base64.d.ts +8 -0
  71. package/dist/es/crypto/base64/base64.mjs +531 -0
  72. package/dist/es/crypto/base64/index.d.ts +53 -0
  73. package/dist/es/crypto/base64/index.mjs +73 -0
  74. package/dist/es/crypto/index.d.ts +8 -0
  75. package/dist/es/crypto/md5/index.d.ts +26 -0
  76. package/dist/es/crypto/md5/index.mjs +44 -0
  77. package/dist/es/crypto/md5/md5.d.ts +11 -0
  78. package/dist/es/crypto/md5/md5.mjs +349 -0
  79. package/dist/es/crypto/sha256/index.d.ts +52 -0
  80. package/dist/es/crypto/sha256/index.mjs +86 -0
  81. package/dist/es/crypto/sha256/sha256.d.ts +82 -0
  82. package/dist/es/crypto/sha256/sha256.mjs +548 -0
  83. package/dist/es/crypto/sm3/index.d.ts +13 -0
  84. package/dist/es/crypto/sm3/index.mjs +24 -0
  85. package/dist/es/crypto/sm3/sm3.d.ts +3 -0
  86. package/dist/es/crypto/sm3/sm3.mjs +197 -0
  87. package/dist/es/crypto/sm4/index.d.ts +56 -0
  88. package/dist/es/crypto/sm4/index.mjs +95 -0
  89. package/dist/es/crypto/sm4/sm4.d.ts +48 -0
  90. package/dist/es/crypto/sm4/sm4.mjs +490 -0
  91. package/dist/es/date/index.d.ts +608 -0
  92. package/dist/es/date/index.mjs +1222 -0
  93. package/dist/es/desensitized/index.d.ts +41 -0
  94. package/dist/es/desensitized/index.mjs +72 -0
  95. package/dist/es/device/index.d.ts +73 -0
  96. package/dist/es/device/index.mjs +140 -0
  97. package/dist/es/dom/index.d.ts +60 -0
  98. package/dist/es/dom/index.mjs +122 -0
  99. package/dist/es/file/index.d.ts +93 -0
  100. package/dist/es/file/index.mjs +327 -0
  101. package/dist/es/function/index.d.ts +26 -0
  102. package/dist/es/function/index.mjs +68 -0
  103. package/dist/es/id/index.d.ts +3 -0
  104. package/dist/es/id/index.mjs +6 -2
  105. package/dist/es/index.d.ts +26 -2
  106. package/dist/es/index.mjs +40 -4
  107. package/dist/es/keycode/index.d.ts +12 -0
  108. package/dist/es/keycode/index.mjs +27 -0
  109. package/dist/es/math/index.d.ts +66 -0
  110. package/dist/es/math/index.mjs +300 -0
  111. package/dist/es/number/index.d.ts +14 -0
  112. package/dist/es/number/index.mjs +31 -0
  113. package/dist/es/object/index.d.ts +84 -0
  114. package/dist/es/object/index.mjs +306 -0
  115. package/dist/es/pagination/index.d.ts +67 -0
  116. package/dist/es/pagination/index.mjs +140 -0
  117. package/dist/es/random/index.d.ts +18 -0
  118. package/dist/es/random/index.mjs +24 -0
  119. package/dist/es/regexp/index.d.ts +63 -0
  120. package/dist/es/regexp/index.mjs +92 -0
  121. package/dist/es/storage/index.d.ts +13 -0
  122. package/dist/es/storage/index.mjs +12 -0
  123. package/dist/es/storage/localStorage.d.ts +21 -0
  124. package/dist/es/storage/localStorage.mjs +32 -0
  125. package/dist/es/storage/sessionStorage.d.ts +21 -0
  126. package/dist/es/storage/sessionStorage.mjs +32 -0
  127. package/dist/es/string/index.d.ts +124 -0
  128. package/dist/es/string/index.mjs +342 -0
  129. package/dist/es/url/index.d.ts +118 -0
  130. package/dist/es/url/index.mjs +243 -0
  131. package/dist/es/validate/index.d.ts +231 -0
  132. package/dist/es/validate/index.mjs +447 -0
  133. package/dist/index.d.ts +2394 -2
  134. package/dist/lib/index.full.umd.js +8059 -29
  135. package/dist/lib/index.full.umd.min.js +2 -2
  136. package/dist/lib/index.full.umd.min.js.map +1 -1
  137. package/dist/resolver/auto-imports.cjs +345 -2
  138. package/dist/resolver/auto-imports.mjs +345 -2
  139. package/dist/resolver/index.cjs +1 -2
  140. package/dist/resolver/index.d.ts +1 -1
  141. package/dist/resolver/index.mjs +1 -2
  142. package/package.json +16 -7
@@ -0,0 +1,197 @@
1
+ /**
2
+ * SM3 纯函数式实现(无类、无实例,闭包隔离状态)
3
+ */
4
+ // 全局常量(只读,无状态)
5
+ const BLOCK_LENGTH = 64;
6
+ const IPAD = new Uint8Array(BLOCK_LENGTH).fill(0x36);
7
+ const OPAD = new Uint8Array(BLOCK_LENGTH).fill(0x5c);
8
+ const IV = new Uint32Array([
9
+ 0x7380166f, 0x4914b2b9, 0x172442d7, 0xda8a0600, 0xa96f30bc, 0x163138aa, 0xe38dee4d, 0xb0fb0e4e,
10
+ ]);
11
+ // 纯函数:循环左移
12
+ function rotl(x, n) {
13
+ const s = n & 31;
14
+ return (x << s) | (x >>> (32 - s));
15
+ }
16
+ // 纯函数:字节数组异或
17
+ function xor(x, y) {
18
+ const result = [];
19
+ for (let i = x.length - 1; i >= 0; i--) {
20
+ result[i] = (x[i] ^ y[i]) & 0xff;
21
+ }
22
+ return result;
23
+ }
24
+ // 纯函数:置换函数 P0
25
+ function P0(X) {
26
+ return X ^ rotl(X, 9) ^ rotl(X, 17);
27
+ }
28
+ // 纯函数:置换函数 P1
29
+ function P1(X) {
30
+ return X ^ rotl(X, 15) ^ rotl(X, 23);
31
+ }
32
+ // 纯函数:补全16进制字符串
33
+ function leftPad(input, num) {
34
+ if (input.length >= num)
35
+ return input;
36
+ return new Array(num - input.length + 1).join("0") + input;
37
+ }
38
+ // 纯函数:字节数组转16进制
39
+ function arrayToHex(arr) {
40
+ return arr
41
+ .map((item) => {
42
+ item = item.toString(16);
43
+ return item.length === 1 ? "0" + item : item;
44
+ })
45
+ .join("");
46
+ }
47
+ // 纯函数:16进制转字节数组
48
+ function hexToArray(hexStr) {
49
+ const words = [];
50
+ let hexStrLength = hexStr.length;
51
+ if (hexStrLength % 2 !== 0) {
52
+ hexStr = leftPad(hexStr, hexStrLength + 1);
53
+ }
54
+ hexStrLength = hexStr.length;
55
+ for (let i = 0; i < hexStrLength; i += 2) {
56
+ words.push(parseInt(hexStr.substr(i, 2), 16));
57
+ }
58
+ return words;
59
+ }
60
+ // 纯函数:UTF8转字节数组
61
+ function utf8ToArray(str) {
62
+ const arr = [];
63
+ for (let i = 0, len = str.length; i < len; i++) {
64
+ const point = str.codePointAt(i);
65
+ if (point <= 0x007f) {
66
+ arr.push(point);
67
+ }
68
+ else if (point <= 0x07ff) {
69
+ arr.push(0xc0 | (point >>> 6));
70
+ arr.push(0x80 | (point & 0x3f));
71
+ }
72
+ else if (point <= 0xd7ff || (point >= 0xe000 && point <= 0xffff)) {
73
+ arr.push(0xe0 | (point >>> 12));
74
+ arr.push(0x80 | ((point >>> 6) & 0x3f));
75
+ arr.push(0x80 | (point & 0x3f));
76
+ }
77
+ else if (point >= 0x010000 && point <= 0x10ffff) {
78
+ i++;
79
+ arr.push(0xf0 | ((point >>> 18) & 0x1c));
80
+ arr.push(0x80 | ((point >>> 12) & 0x3f));
81
+ arr.push(0x80 | ((point >>> 6) & 0x3f));
82
+ arr.push(0x80 | (point & 0x3f));
83
+ }
84
+ else {
85
+ arr.push(point);
86
+ throw new Error("input is not supported");
87
+ }
88
+ }
89
+ return arr;
90
+ }
91
+ // 核心纯函数:SM3哈希计算(闭包隔离状态)
92
+ function sm3Core(array) {
93
+ // 每次调用都创建全新的局部状态(隔离关键)
94
+ let len = array.length * 8;
95
+ let k = len % 512;
96
+ k = k >= 448 ? 512 - (k % 448) - 1 : 448 - k - 1;
97
+ const kArr = new Array((k - 7) / 8).fill(0);
98
+ const lenArr = new Array(8).fill(0);
99
+ let lenBin = len.toString(2);
100
+ for (let i = 7; i >= 0; i--) {
101
+ if (lenBin.length > 8) {
102
+ const start = lenBin.length - 8;
103
+ lenArr[i] = parseInt(lenBin.substr(start), 2);
104
+ lenBin = lenBin.substr(0, start);
105
+ }
106
+ else if (lenBin.length > 0) {
107
+ lenArr[i] = parseInt(lenBin, 2);
108
+ lenBin = "";
109
+ }
110
+ }
111
+ const m = new Uint8Array([...array, 0x80, ...kArr, ...lenArr]);
112
+ const dataView = new DataView(m.buffer, 0);
113
+ const n = m.length / 64;
114
+ const V = new Uint32Array(IV); // 全新初始向量(每次调用重新创建)
115
+ const W = new Uint32Array(68); // 全新消息扩展数组
116
+ const M = new Uint32Array(64); // 全新W'数组
117
+ // 以下计算逻辑和原代码一致,仅操作局部变量
118
+ for (let i = 0; i < n; i++) {
119
+ W.fill(0);
120
+ M.fill(0);
121
+ const start = 16 * i;
122
+ for (let j = 0; j < 16; j++) {
123
+ W[j] = dataView.getUint32((start + j) * 4, false);
124
+ }
125
+ for (let j = 16; j < 68; j++) {
126
+ W[j] = P1(W[j - 16] ^ W[j - 9] ^ rotl(W[j - 3], 15)) ^ rotl(W[j - 13], 7) ^ W[j - 6];
127
+ }
128
+ for (let j = 0; j < 64; j++) {
129
+ M[j] = W[j] ^ W[j + 4];
130
+ }
131
+ const T1 = 0x79cc4519;
132
+ const T2 = 0x7a879d8a;
133
+ let A = V[0], B = V[1], C = V[2], D = V[3];
134
+ let E = V[4], F = V[5], G = V[6], H = V[7];
135
+ let SS1, SS2, TT1, TT2, T;
136
+ for (let j = 0; j < 64; j++) {
137
+ T = j <= 15 ? T1 : T2;
138
+ SS1 = rotl((rotl(A, 12) + E + rotl(T, j)) & 0xffffffff, 7);
139
+ SS2 = SS1 ^ rotl(A, 12);
140
+ const FFj = j <= 15 ? A ^ B ^ C : (A & B) | (A & C) | (B & C);
141
+ const GGj = j <= 15 ? E ^ F ^ G : (E & F) | (~E & G);
142
+ TT1 = (FFj + D + SS2 + M[j]) & 0xffffffff;
143
+ TT2 = (GGj + H + SS1 + W[j]) & 0xffffffff;
144
+ D = C;
145
+ C = rotl(B, 9);
146
+ B = A;
147
+ A = TT1;
148
+ H = G;
149
+ G = rotl(F, 19);
150
+ F = E;
151
+ E = P0(TT2);
152
+ }
153
+ V[0] ^= A;
154
+ V[1] ^= B;
155
+ V[2] ^= C;
156
+ V[3] ^= D;
157
+ V[4] ^= E;
158
+ V[5] ^= F;
159
+ V[6] ^= G;
160
+ V[7] ^= H;
161
+ }
162
+ const result = [];
163
+ for (let i = 0; i < V.length; i++) {
164
+ result.push((V[i] & 0xff000000) >>> 24, (V[i] & 0xff0000) >>> 16, (V[i] & 0xff00) >>> 8, V[i] & 0xff);
165
+ }
166
+ return result;
167
+ }
168
+ // 纯函数:HMAC-SM3计算
169
+ function encryptHmac(input, key) {
170
+ let processedKey = key.length > BLOCK_LENGTH ? sm3Core(key) : [...key];
171
+ while (processedKey.length < BLOCK_LENGTH) {
172
+ processedKey.push(0);
173
+ }
174
+ const iPadKey = xor(processedKey, IPAD);
175
+ const oPadKey = xor(processedKey, OPAD);
176
+ const innerHash = sm3Core([...iPadKey, ...input]);
177
+ return sm3Core([...oPadKey, ...innerHash]);
178
+ }
179
+ // 对外暴露的核心函数(兼容原调用方式)
180
+ function encrypt(input, key) {
181
+ const inputArr = typeof input === "string" ? utf8ToArray(input) : Array.prototype.slice.call(input);
182
+ if (!key) {
183
+ const hashArr = sm3Core(inputArr);
184
+ return arrayToHex(hashArr);
185
+ }
186
+ else {
187
+ const keyArr = typeof key === "string"
188
+ ? /^[0-9a-fA-F]+$/.test(key)
189
+ ? hexToArray(key)
190
+ : utf8ToArray(key)
191
+ : Array.prototype.slice.call(key);
192
+ const hmacArr = encryptHmac(inputArr, keyArr);
193
+ return arrayToHex(hmacArr);
194
+ }
195
+ }
196
+
197
+ export { encrypt, encryptHmac as encrypt_hmac };
@@ -0,0 +1,56 @@
1
+ import * as sm4 from "./sm4.js";
2
+ /**
3
+ * sm4传参和返回的类型,不管是传参还是返回值固定是这几个
4
+ */
5
+ export type SM4DataType = string | Uint8Array | ArrayBuffer | number[];
6
+ /**
7
+ * sm4通用配置
8
+ */
9
+ export interface SM4Options {
10
+ mode?: keyof typeof sm4.MODE;
11
+ iv?: SM4DataType;
12
+ padding?: "pkcs#7";
13
+ output?: keyof typeof sm4.OUTPUT;
14
+ }
15
+ /**
16
+ * sm4 加密
17
+ * @param {string} str 字符串
18
+ * @param {string} key 秘钥
19
+ * @param {Object} options 配置
20
+ * @returns {string} 加密后的字符串
21
+ */
22
+ export declare function sm4Encrypt(str: string, key: SM4DataType, options?: SM4Options): SM4DataType;
23
+ /**
24
+ * sm4 解密
25
+ * @param {string} str 字符串
26
+ * @param {string} key 秘钥
27
+ * @param {Object} options 配置
28
+ * @returns {string} 解密后的数据
29
+ */
30
+ export declare function sm4Decrypt(str: string, key: SM4DataType, options?: SM4Options): SM4DataType;
31
+ /**
32
+ * 生成sm4的key
33
+ * @param {string} inputFormat 输入类型 可以任意字符串,其中固定的uint8array、array、hex这3个字符串,会对应生成类型数据
34
+ * @returns {SM4DataType} 生成的key
35
+ */
36
+ export declare const generateSM4Key: (inputFormat?: string) => SM4DataType;
37
+ /**
38
+ * 生成sm4的iv
39
+ * @param {string} inputFormat 输入类型 可以任意字符串,其中固定的uint8array、array、hex这3个字符串,会对应生成类型数据
40
+ * @returns {SM4DataType} 生成的iv
41
+ */
42
+ export declare const generateSM4Iv: (inputFormat?: string) => SM4DataType;
43
+ export declare const SM4: {
44
+ MODE: {
45
+ ECB: string;
46
+ CBC: string;
47
+ };
48
+ PADDING: string;
49
+ OUTPUT: {
50
+ HEX: string;
51
+ UTF8: string;
52
+ ARRAY: string;
53
+ UINT8ARRAY: string;
54
+ ARRAYBUFFER: string;
55
+ };
56
+ };
@@ -0,0 +1,95 @@
1
+ import { generateKey, generateIv, OUTPUT, PADDING, MODE, encrypt, decrypt } from './sm4.mjs';
2
+
3
+ /**
4
+ * sm4 加密
5
+ * @param {string} str 字符串
6
+ * @param {string} key 秘钥
7
+ * @param {Object} options 配置
8
+ * @returns {string} 加密后的字符串
9
+ */
10
+ function sm4Encrypt(str, key, options) {
11
+ _validateSM4Options(options, "encrypt");
12
+ return encrypt(str, key, options);
13
+ }
14
+ /**
15
+ * sm4 解密
16
+ * @param {string} str 字符串
17
+ * @param {string} key 秘钥
18
+ * @param {Object} options 配置
19
+ * @returns {string} 解密后的数据
20
+ */
21
+ function sm4Decrypt(str, key, options) {
22
+ _validateSM4Options(options, "decrypt");
23
+ return decrypt(str, key, options);
24
+ }
25
+ /**
26
+ * 生成sm4的key
27
+ * @param {string} inputFormat 输入类型 可以任意字符串,其中固定的uint8array、array、hex这3个字符串,会对应生成类型数据
28
+ * @returns {SM4DataType} 生成的key
29
+ */
30
+ const generateSM4Key = generateKey;
31
+ /**
32
+ * 生成sm4的iv
33
+ * @param {string} inputFormat 输入类型 可以任意字符串,其中固定的uint8array、array、hex这3个字符串,会对应生成类型数据
34
+ * @returns {SM4DataType} 生成的iv
35
+ */
36
+ const generateSM4Iv = generateIv;
37
+ /**
38
+ * 校验SM4配置参数的合法性
39
+ * @param options 配置项
40
+ * @param operation 操作类型(encrypt/decrypt)
41
+ */
42
+ function _validateSM4Options(options = {}, operation) {
43
+ const { mode = MODE.ECB, iv } = options;
44
+ // 1. 校验模式是否合法
45
+ const validModes = Object.values(MODE);
46
+ if (!validModes.includes(mode)) {
47
+ throw new Error(`sm4${operation} 方法错误:不支持的加密模式 "${mode}",仅支持 ${validModes.join("/")}`);
48
+ }
49
+ // 2. CBC模式必须传IV
50
+ if (mode === MODE.CBC && !iv) {
51
+ throw new Error(`sm4${operation} 方法错误:CBC 模式必须传入 IV 初始向量`);
52
+ }
53
+ // 3. ECB模式禁止传IV(避免误用)
54
+ if (mode === MODE.ECB && iv !== undefined) {
55
+ throw new Error(`sm4${operation} 方法错误:ECB 模式不需要传入 IV,请勿传递iv参数`);
56
+ }
57
+ // 4. 校验IV长度(如果传了IV)
58
+ if (iv) {
59
+ let ivLength;
60
+ if (typeof iv === "string") {
61
+ // hex字符串:16字节对应32位hex
62
+ ivLength = iv.length === 32 ? 16 : iv.length;
63
+ }
64
+ else if (iv instanceof ArrayBuffer) {
65
+ ivLength = iv.byteLength;
66
+ }
67
+ else if (iv instanceof Uint8Array) {
68
+ ivLength = iv.length;
69
+ }
70
+ else if (Array.isArray(iv)) {
71
+ ivLength = iv.length;
72
+ }
73
+ else {
74
+ ivLength = 0;
75
+ }
76
+ if (ivLength !== 16) {
77
+ throw new Error(`SM4${operation}错误:IV 长度必须为 16 字节,当前长度为 ${ivLength}`);
78
+ }
79
+ }
80
+ // 5. 校验填充模式(仅允许pkcs#7)
81
+ if (options.padding && options.padding !== String(PADDING)) {
82
+ throw new Error(`SM4${operation}错误:仅支持 pkcs#7 填充模式,当前传入 ${String(options.padding)}`);
83
+ }
84
+ }
85
+ // sm4的配置
86
+ const SM4 = {
87
+ // sm4的模式
88
+ MODE: MODE,
89
+ // sm4的填充
90
+ PADDING: PADDING,
91
+ // sm4的输出
92
+ OUTPUT: OUTPUT,
93
+ };
94
+
95
+ export { SM4, generateSM4Iv, generateSM4Key, sm4Decrypt, sm4Encrypt };
@@ -0,0 +1,48 @@
1
+ /**
2
+ * 生成 SM4 CBC 模式专用的安全随机 IV(16字节)
3
+ * @param {string} [outputFormat=SM4_OUTPUT_HEX] - 输出格式:hex/uint8array/array/arraybuffer
4
+ * @returns {string|Uint8Array|Array|ArrayBuffer} 随机IV
5
+ */
6
+ export function generateIv(outputFormat?: string): string | Uint8Array | any[] | ArrayBuffer;
7
+ /**
8
+ * 生成 SM4 标准密钥(16字节/32位16进制字符串)
9
+ * @param {string} [outputFormat=SM4_OUTPUT_HEX] - 输出格式:hex/uint8array/array/arraybuffer
10
+ * @returns {string|Uint8Array|number[]|ArrayBuffer} 16字节SM4密钥
11
+ */
12
+ export function generateKey(outputFormat?: string): string | Uint8Array | number[] | ArrayBuffer;
13
+ /**
14
+ * SM4加密
15
+ * @param {string|Array|Uint8Array|ArrayBuffer} input - 输入数据(字符串/字节)
16
+ * @param {string|Array|Uint8Array|ArrayBuffer} key - 16字节密钥
17
+ * @param {Object} [options] - 选项
18
+ * @returns {string|Array|Uint8Array|ArrayBuffer} 加密结果
19
+ */
20
+ export function encrypt(input: string | any[] | Uint8Array | ArrayBuffer, key: string | any[] | Uint8Array | ArrayBuffer, options?: Object): string | any[] | Uint8Array | ArrayBuffer;
21
+ /**
22
+ * SM4解密
23
+ * @param {string|Array|Uint8Array|ArrayBuffer} input - 加密数据(16进制字符串/字节)
24
+ * @param {string|Array|Uint8Array|ArrayBuffer} key - 16字节密钥
25
+ * @param {Object} [options] - 选项
26
+ * @returns {string|Array|Uint8Array|ArrayBuffer} 解密结果
27
+ */
28
+ export function decrypt(input: string | any[] | Uint8Array | ArrayBuffer, key: string | any[] | Uint8Array | ArrayBuffer, options?: Object): string | any[] | Uint8Array | ArrayBuffer;
29
+ export namespace MODE {
30
+ export { SM4_MODE_ECB as ECB };
31
+ export { SM4_MODE_CBC as CBC };
32
+ }
33
+ export const PADDING: "pkcs#7";
34
+ export namespace OUTPUT {
35
+ export { SM4_OUTPUT_HEX as HEX };
36
+ export { SM4_OUTPUT_UTF8 as UTF8 };
37
+ export { SM4_OUTPUT_ARRAY as ARRAY };
38
+ export { SM4_OUTPUT_UINT8ARRAY as UINT8ARRAY };
39
+ export { SM4_OUTPUT_ARRAYBUFFER as ARRAYBUFFER };
40
+ }
41
+ declare const SM4_MODE_ECB: "ecb";
42
+ declare const SM4_MODE_CBC: "cbc";
43
+ declare const SM4_OUTPUT_HEX: "hex";
44
+ declare const SM4_OUTPUT_UTF8: "utf8";
45
+ declare const SM4_OUTPUT_ARRAY: "array";
46
+ declare const SM4_OUTPUT_UINT8ARRAY: "uint8array";
47
+ declare const SM4_OUTPUT_ARRAYBUFFER: "arraybuffer";
48
+ export {};