szld-libs 0.2.48 → 0.2.50
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/dist/szld-components.es.js +9318 -9214
- package/dist/szld-components.umd.js +48 -48
- package/es/index.js +4 -1
- package/es/main.d.ts +4 -3
- package/es/main.js +16 -14
- package/es/utils/hmacSM3.d.ts +20 -0
- package/es/utils/hmacSM3.js +173 -0
- package/lib/index.js +3 -0
- package/lib/main.d.ts +4 -3
- package/lib/main.js +6 -4
- package/lib/utils/hmacSM3.d.ts +20 -0
- package/lib/utils/hmacSM3.js +172 -0
- package/package.json +2 -1
package/es/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import ReactDOM from "react-dom/client";
|
|
|
4
4
|
import { BrowserRouter } from "react-router-dom";
|
|
5
5
|
import { App, Form, Table, Flex, Button } from "antd";
|
|
6
6
|
import useConfig from "./hooks/useConfig";
|
|
7
|
-
import { useRowSelection, useChangePwd, BackHeader, SearchTable, CreateForm, CustomPagination } from "./main";
|
|
7
|
+
import { useRowSelection, useChangePwd, HmacSM3, BackHeader, SearchTable, CreateForm, CustomPagination } from "./main";
|
|
8
8
|
let key = "U2FsdGVkX1/dG1NSXNR9hnp3Ech/v6Gh8CDDJxgBm1EPFQel12ySIf84ARXCPwTae7TzwgPvjOyE3S5rAEzl/wAZmId6pbezpFeFcJqxdmIl3FeluYHFxJzQHDETTvrr3G/REvv00kHptOVwg6ecjPH6yk7PNit0sWTBLorROxLxMD8lVDmOA66p7Zp4QnYzqScYJGFbutmfHYXfBRBe1Q2UKummJ798svNY5SIwEwl4spzgyWmhARtuyq4zhysFrj/xODuNDjtwitA6XfX566WcZkj3F+2P+mkYzDYOhXXaomnlybjrZ2hEHfcczQhUfJd89O8PNIuEWo24wjYRgMdKlw5CWSeocFCqV7ZJ/CV/7vNRcaO4awKlFNobLikkwDznxpcX+4UEej+ED+pgfmPQLsKedcfEscStkSAZXaD5pBRTiFU9xGLfDt6seUrEnMBeXkpMIY9j1SZDDK18/G7lSHjDQMZYZP6sfLdBdwY=";
|
|
9
9
|
const Demo = () => {
|
|
10
10
|
useConfig(key);
|
|
@@ -128,6 +128,9 @@ const Demo = () => {
|
|
|
128
128
|
const unitText = "条@";
|
|
129
129
|
const jumpText = "跳至@";
|
|
130
130
|
const pageText = "页@";
|
|
131
|
+
const sm3key = "Aa123456#";
|
|
132
|
+
const message = "username=admin×tamp=1758782465&modelid=19955BC7B61A43B3A982F0B2053ABC34";
|
|
133
|
+
HmacSM3.hmac(sm3key, message);
|
|
131
134
|
return /* @__PURE__ */ jsxs("div", { style: { height: "100vh", display: "flex", flexDirection: "column", gap: 20 }, children: [
|
|
132
135
|
/* @__PURE__ */ jsx(BackHeader, { title: "页头组件", isBack: true }),
|
|
133
136
|
/* @__PURE__ */ jsxs(Flex, { gap: 20, align: "center", children: [
|
package/es/main.d.ts
CHANGED
|
@@ -14,11 +14,12 @@ import * as FormRules from './utils/formRules';
|
|
|
14
14
|
import compressionImage from './utils/image-compression';
|
|
15
15
|
import * as utils from './utils/index';
|
|
16
16
|
import * as verfyCode from './utils/verify-code';
|
|
17
|
+
import AES from './utils/aes';
|
|
18
|
+
import HmacSHA512 from './utils/hmacSHA512';
|
|
19
|
+
import HmacSM3 from './utils/hmacSM3';
|
|
17
20
|
import useCaptcha from './hooks/useCaptcha';
|
|
18
21
|
import useChangePwd from './hooks/useChangePwd';
|
|
19
22
|
import useConfig from './hooks/useConfig';
|
|
20
23
|
import useRemember from './hooks/useRemember';
|
|
21
24
|
import useRowSelection from './hooks/useRowSelection';
|
|
22
|
-
|
|
23
|
-
import HmacSHA512 from './utils/hmacSHA512';
|
|
24
|
-
export { AES, AuthButton, BackHeader, compressionImage, CoralButton, CreateForm, download, EditTable, fileType, FormRules, HmacSHA512, LoopSlide, SearchTable, showWorkFlow, UploadFile, useCaptcha, useChangePwd, useConfig, useRemember, useRowSelection, utils, verfyCode, WorkFlowNode, CustomPagination, };
|
|
25
|
+
export { AES, AuthButton, BackHeader, compressionImage, CoralButton, CreateForm, download, EditTable, fileType, FormRules, HmacSHA512, HmacSM3, LoopSlide, SearchTable, showWorkFlow, UploadFile, useCaptcha, useChangePwd, useConfig, useRemember, useRowSelection, utils, verfyCode, WorkFlowNode, CustomPagination, };
|
package/es/main.js
CHANGED
|
@@ -14,15 +14,16 @@ import * as formRules from "./utils/formRules";
|
|
|
14
14
|
import { default as default12 } from "./utils/image-compression";
|
|
15
15
|
import * as index from "./utils/index";
|
|
16
16
|
import * as verifyCode from "./utils/verify-code";
|
|
17
|
-
import { default as default13 } from "./
|
|
18
|
-
import { default as default14 } from "./
|
|
19
|
-
import { default as default15 } from "./
|
|
20
|
-
import { default as default16 } from "./hooks/
|
|
21
|
-
import { default as default17 } from "./hooks/
|
|
22
|
-
import { default as default18 } from "./
|
|
23
|
-
import { default as default19 } from "./
|
|
17
|
+
import { default as default13 } from "./utils/aes";
|
|
18
|
+
import { default as default14 } from "./utils/hmacSHA512";
|
|
19
|
+
import { default as default15 } from "./utils/hmacSM3";
|
|
20
|
+
import { default as default16 } from "./hooks/useCaptcha";
|
|
21
|
+
import { default as default17 } from "./hooks/useChangePwd";
|
|
22
|
+
import { default as default18 } from "./hooks/useConfig";
|
|
23
|
+
import { default as default19 } from "./hooks/useRemember";
|
|
24
|
+
import { default as default20 } from "./hooks/useRowSelection";
|
|
24
25
|
export {
|
|
25
|
-
|
|
26
|
+
default13 as AES,
|
|
26
27
|
default7 as AuthButton,
|
|
27
28
|
default2 as BackHeader,
|
|
28
29
|
default8 as CoralButton,
|
|
@@ -30,7 +31,8 @@ export {
|
|
|
30
31
|
default11 as CustomPagination,
|
|
31
32
|
default6 as EditTable,
|
|
32
33
|
formRules as FormRules,
|
|
33
|
-
|
|
34
|
+
default14 as HmacSHA512,
|
|
35
|
+
default15 as HmacSM3,
|
|
34
36
|
default9 as LoopSlide,
|
|
35
37
|
default4 as SearchTable,
|
|
36
38
|
default5 as UploadFile,
|
|
@@ -39,11 +41,11 @@ export {
|
|
|
39
41
|
download,
|
|
40
42
|
filetype as fileType,
|
|
41
43
|
default10 as showWorkFlow,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
default16 as useCaptcha,
|
|
45
|
+
default17 as useChangePwd,
|
|
46
|
+
default18 as useConfig,
|
|
47
|
+
default19 as useRemember,
|
|
48
|
+
default20 as useRowSelection,
|
|
47
49
|
index as utils,
|
|
48
50
|
verifyCode as verfyCode
|
|
49
51
|
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HMAC-SM3 实现
|
|
3
|
+
*/
|
|
4
|
+
declare class HmacSM3 {
|
|
5
|
+
private key;
|
|
6
|
+
constructor(key: string | Uint8Array);
|
|
7
|
+
/**
|
|
8
|
+
* 计算HMAC-SM3值
|
|
9
|
+
*/
|
|
10
|
+
digest(message: string | Uint8Array): Uint8Array;
|
|
11
|
+
/**
|
|
12
|
+
* 计算HMAC-SM3值并返回十六进制字符串
|
|
13
|
+
*/
|
|
14
|
+
digestHex(message: string | Uint8Array): string;
|
|
15
|
+
/**
|
|
16
|
+
* 静态方法:快速计算HMAC-SM3
|
|
17
|
+
*/
|
|
18
|
+
static hmac(key: string | Uint8Array, message: string | Uint8Array): string;
|
|
19
|
+
}
|
|
20
|
+
export default HmacSM3;
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => {
|
|
4
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
return value;
|
|
6
|
+
};
|
|
7
|
+
const _SM3 = class {
|
|
8
|
+
static rotateLeft(x, n) {
|
|
9
|
+
return x << n | x >>> 32 - n;
|
|
10
|
+
}
|
|
11
|
+
static FFj(X, Y, Z, j) {
|
|
12
|
+
if (j >= 0 && j <= 15) {
|
|
13
|
+
return X ^ Y ^ Z;
|
|
14
|
+
} else {
|
|
15
|
+
return X & Y | X & Z | Y & Z;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
static GGj(X, Y, Z, j) {
|
|
19
|
+
if (j >= 0 && j <= 15) {
|
|
20
|
+
return X ^ Y ^ Z;
|
|
21
|
+
} else {
|
|
22
|
+
return X & Y | ~X & Z;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
static P0(X) {
|
|
26
|
+
return X ^ _SM3.rotateLeft(X, 9) ^ _SM3.rotateLeft(X, 17);
|
|
27
|
+
}
|
|
28
|
+
static P1(X) {
|
|
29
|
+
return X ^ _SM3.rotateLeft(X, 15) ^ _SM3.rotateLeft(X, 23);
|
|
30
|
+
}
|
|
31
|
+
static pad(message) {
|
|
32
|
+
const bitLength = message.length * 8;
|
|
33
|
+
const paddingLength = (448 - (bitLength + 1) % 512 + 512) % 512;
|
|
34
|
+
const totalLength = (bitLength + 1 + paddingLength + 64) / 8;
|
|
35
|
+
const padded = new Uint8Array(totalLength);
|
|
36
|
+
padded.set(message);
|
|
37
|
+
padded[message.length] = 128;
|
|
38
|
+
const lengthBytes = new Uint8Array(8);
|
|
39
|
+
const lengthView = new DataView(lengthBytes.buffer);
|
|
40
|
+
lengthView.setBigUint64(0, BigInt(bitLength), false);
|
|
41
|
+
padded.set(lengthBytes, totalLength - 8);
|
|
42
|
+
return padded;
|
|
43
|
+
}
|
|
44
|
+
static processBlock(block, state) {
|
|
45
|
+
const W = new Uint32Array(68);
|
|
46
|
+
const W1 = new Uint32Array(64);
|
|
47
|
+
for (let i = 0; i < 16; i++) {
|
|
48
|
+
const view = new DataView(block.buffer, block.byteOffset + i * 4, 4);
|
|
49
|
+
W[i] = view.getUint32(0, false);
|
|
50
|
+
}
|
|
51
|
+
for (let j = 16; j < 68; j++) {
|
|
52
|
+
W[j] = _SM3.P1(W[j - 16] ^ W[j - 9] ^ _SM3.rotateLeft(W[j - 3], 15)) ^ _SM3.rotateLeft(W[j - 13], 7) ^ W[j - 6];
|
|
53
|
+
}
|
|
54
|
+
for (let j = 0; j < 64; j++) {
|
|
55
|
+
W1[j] = W[j] ^ W[j + 4];
|
|
56
|
+
}
|
|
57
|
+
let A = state[0];
|
|
58
|
+
let B = state[1];
|
|
59
|
+
let C = state[2];
|
|
60
|
+
let D = state[3];
|
|
61
|
+
let E = state[4];
|
|
62
|
+
let F = state[5];
|
|
63
|
+
let G = state[6];
|
|
64
|
+
let H = state[7];
|
|
65
|
+
for (let j = 0; j < 64; j++) {
|
|
66
|
+
const SS1 = _SM3.rotateLeft(_SM3.rotateLeft(A, 12) + E + _SM3.rotateLeft(_SM3.T[j], j), 7);
|
|
67
|
+
const SS2 = SS1 ^ _SM3.rotateLeft(A, 12);
|
|
68
|
+
const TT1 = _SM3.FFj(A, B, C, j) + D + SS2 + W1[j];
|
|
69
|
+
const TT2 = _SM3.GGj(E, F, G, j) + H + SS1 + W[j];
|
|
70
|
+
D = C;
|
|
71
|
+
C = _SM3.rotateLeft(B, 9);
|
|
72
|
+
B = A;
|
|
73
|
+
A = TT1;
|
|
74
|
+
H = G;
|
|
75
|
+
G = _SM3.rotateLeft(F, 19);
|
|
76
|
+
F = E;
|
|
77
|
+
E = _SM3.P0(TT2);
|
|
78
|
+
}
|
|
79
|
+
state[0] ^= A;
|
|
80
|
+
state[1] ^= B;
|
|
81
|
+
state[2] ^= C;
|
|
82
|
+
state[3] ^= D;
|
|
83
|
+
state[4] ^= E;
|
|
84
|
+
state[5] ^= F;
|
|
85
|
+
state[6] ^= G;
|
|
86
|
+
state[7] ^= H;
|
|
87
|
+
}
|
|
88
|
+
static hash(message) {
|
|
89
|
+
const padded = _SM3.pad(message);
|
|
90
|
+
const state = new Uint32Array(_SM3.IV);
|
|
91
|
+
for (let i = 0; i < padded.length; i += 64) {
|
|
92
|
+
const block = padded.slice(i, i + 64);
|
|
93
|
+
_SM3.processBlock(block, state);
|
|
94
|
+
}
|
|
95
|
+
const result = new Uint8Array(32);
|
|
96
|
+
const resultView = new DataView(result.buffer);
|
|
97
|
+
for (let i = 0; i < 8; i++) {
|
|
98
|
+
resultView.setUint32(i * 4, state[i], false);
|
|
99
|
+
}
|
|
100
|
+
return result;
|
|
101
|
+
}
|
|
102
|
+
static hashHex(message) {
|
|
103
|
+
const msgArray = typeof message === "string" ? new TextEncoder().encode(message) : message;
|
|
104
|
+
const hashBytes = _SM3.hash(msgArray);
|
|
105
|
+
return Array.from(hashBytes).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
let SM3 = _SM3;
|
|
109
|
+
__publicField(SM3, "IV", new Uint32Array([
|
|
110
|
+
1937774191,
|
|
111
|
+
1226093241,
|
|
112
|
+
388252375,
|
|
113
|
+
3666478592,
|
|
114
|
+
2842636476,
|
|
115
|
+
372324522,
|
|
116
|
+
3817729613,
|
|
117
|
+
2969243214
|
|
118
|
+
]));
|
|
119
|
+
__publicField(SM3, "T", new Uint32Array(64));
|
|
120
|
+
(() => {
|
|
121
|
+
for (let j = 0; j < 16; j++) {
|
|
122
|
+
_SM3.T[j] = 2043430169;
|
|
123
|
+
}
|
|
124
|
+
for (let j = 16; j < 64; j++) {
|
|
125
|
+
_SM3.T[j] = 2055708042;
|
|
126
|
+
}
|
|
127
|
+
})();
|
|
128
|
+
class HmacSM3 {
|
|
129
|
+
constructor(key) {
|
|
130
|
+
__publicField(this, "key");
|
|
131
|
+
this.key = typeof key === "string" ? new TextEncoder().encode(key) : key;
|
|
132
|
+
}
|
|
133
|
+
digest(message) {
|
|
134
|
+
const msgArray = typeof message === "string" ? new TextEncoder().encode(message) : message;
|
|
135
|
+
const blockSize = 64;
|
|
136
|
+
let keyBuffer;
|
|
137
|
+
if (this.key.length > blockSize) {
|
|
138
|
+
keyBuffer = SM3.hash(this.key);
|
|
139
|
+
} else {
|
|
140
|
+
keyBuffer = new Uint8Array(blockSize);
|
|
141
|
+
keyBuffer.set(this.key);
|
|
142
|
+
for (let i = this.key.length; i < blockSize; i++) {
|
|
143
|
+
keyBuffer[i] = 0;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
const ipadKey = new Uint8Array(blockSize);
|
|
147
|
+
const opadKey = new Uint8Array(blockSize);
|
|
148
|
+
for (let i = 0; i < blockSize; i++) {
|
|
149
|
+
ipadKey[i] = keyBuffer[i] ^ 54;
|
|
150
|
+
opadKey[i] = keyBuffer[i] ^ 92;
|
|
151
|
+
}
|
|
152
|
+
const innerData = new Uint8Array(ipadKey.length + msgArray.length);
|
|
153
|
+
innerData.set(ipadKey);
|
|
154
|
+
innerData.set(msgArray, ipadKey.length);
|
|
155
|
+
const innerHash = SM3.hash(innerData);
|
|
156
|
+
const outerData = new Uint8Array(opadKey.length + innerHash.length);
|
|
157
|
+
outerData.set(opadKey);
|
|
158
|
+
outerData.set(innerHash, opadKey.length);
|
|
159
|
+
const finalHash = SM3.hash(outerData);
|
|
160
|
+
return finalHash;
|
|
161
|
+
}
|
|
162
|
+
digestHex(message) {
|
|
163
|
+
const hashBytes = this.digest(message);
|
|
164
|
+
return Array.from(hashBytes).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
165
|
+
}
|
|
166
|
+
static hmac(key, message) {
|
|
167
|
+
const hmac = new HmacSM3(key);
|
|
168
|
+
return hmac.digestHex(message);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
export {
|
|
172
|
+
HmacSM3 as default
|
|
173
|
+
};
|
package/lib/index.js
CHANGED
|
@@ -129,6 +129,9 @@ const Demo = () => {
|
|
|
129
129
|
const unitText = "条@";
|
|
130
130
|
const jumpText = "跳至@";
|
|
131
131
|
const pageText = "页@";
|
|
132
|
+
const sm3key = "Aa123456#";
|
|
133
|
+
const message = "username=admin×tamp=1758782465&modelid=19955BC7B61A43B3A982F0B2053ABC34";
|
|
134
|
+
main.HmacSM3.hmac(sm3key, message);
|
|
132
135
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { height: "100vh", display: "flex", flexDirection: "column", gap: 20 }, children: [
|
|
133
136
|
/* @__PURE__ */ jsxRuntime.jsx(main.BackHeader, { title: "页头组件", isBack: true }),
|
|
134
137
|
/* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { gap: 20, align: "center", children: [
|
package/lib/main.d.ts
CHANGED
|
@@ -14,11 +14,12 @@ import * as FormRules from './utils/formRules';
|
|
|
14
14
|
import compressionImage from './utils/image-compression';
|
|
15
15
|
import * as utils from './utils/index';
|
|
16
16
|
import * as verfyCode from './utils/verify-code';
|
|
17
|
+
import AES from './utils/aes';
|
|
18
|
+
import HmacSHA512 from './utils/hmacSHA512';
|
|
19
|
+
import HmacSM3 from './utils/hmacSM3';
|
|
17
20
|
import useCaptcha from './hooks/useCaptcha';
|
|
18
21
|
import useChangePwd from './hooks/useChangePwd';
|
|
19
22
|
import useConfig from './hooks/useConfig';
|
|
20
23
|
import useRemember from './hooks/useRemember';
|
|
21
24
|
import useRowSelection from './hooks/useRowSelection';
|
|
22
|
-
|
|
23
|
-
import HmacSHA512 from './utils/hmacSHA512';
|
|
24
|
-
export { AES, AuthButton, BackHeader, compressionImage, CoralButton, CreateForm, download, EditTable, fileType, FormRules, HmacSHA512, LoopSlide, SearchTable, showWorkFlow, UploadFile, useCaptcha, useChangePwd, useConfig, useRemember, useRowSelection, utils, verfyCode, WorkFlowNode, CustomPagination, };
|
|
25
|
+
export { AES, AuthButton, BackHeader, compressionImage, CoralButton, CreateForm, download, EditTable, fileType, FormRules, HmacSHA512, HmacSM3, LoopSlide, SearchTable, showWorkFlow, UploadFile, useCaptcha, useChangePwd, useConfig, useRemember, useRowSelection, utils, verfyCode, WorkFlowNode, CustomPagination, };
|
package/lib/main.js
CHANGED
|
@@ -16,13 +16,14 @@ const formRules = require("./utils/formRules");
|
|
|
16
16
|
const imageCompression = require("./utils/image-compression");
|
|
17
17
|
const index = require("./utils/index");
|
|
18
18
|
const verifyCode = require("./utils/verify-code");
|
|
19
|
+
const aes = require("./utils/aes");
|
|
20
|
+
const hmacSHA512 = require("./utils/hmacSHA512");
|
|
21
|
+
const hmacSM3 = require("./utils/hmacSM3");
|
|
19
22
|
const useCaptcha = require("./hooks/useCaptcha");
|
|
20
23
|
const useChangePwd = require("./hooks/useChangePwd");
|
|
21
24
|
const useConfig = require("./hooks/useConfig");
|
|
22
25
|
const useRemember = require("./hooks/useRemember");
|
|
23
26
|
const useRowSelection = require("./hooks/useRowSelection");
|
|
24
|
-
const aes = require("./utils/aes");
|
|
25
|
-
const hmacSHA512 = require("./utils/hmacSHA512");
|
|
26
27
|
function _interopNamespaceDefault(e) {
|
|
27
28
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
28
29
|
if (e) {
|
|
@@ -64,10 +65,11 @@ exports.FormRules = formRules__namespace;
|
|
|
64
65
|
exports.compressionImage = imageCompression;
|
|
65
66
|
exports.utils = index__namespace;
|
|
66
67
|
exports.verfyCode = verifyCode__namespace;
|
|
68
|
+
exports.AES = aes;
|
|
69
|
+
exports.HmacSHA512 = hmacSHA512;
|
|
70
|
+
exports.HmacSM3 = hmacSM3;
|
|
67
71
|
exports.useCaptcha = useCaptcha;
|
|
68
72
|
exports.useChangePwd = useChangePwd;
|
|
69
73
|
exports.useConfig = useConfig;
|
|
70
74
|
exports.useRemember = useRemember;
|
|
71
75
|
exports.useRowSelection = useRowSelection;
|
|
72
|
-
exports.AES = aes;
|
|
73
|
-
exports.HmacSHA512 = hmacSHA512;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HMAC-SM3 实现
|
|
3
|
+
*/
|
|
4
|
+
declare class HmacSM3 {
|
|
5
|
+
private key;
|
|
6
|
+
constructor(key: string | Uint8Array);
|
|
7
|
+
/**
|
|
8
|
+
* 计算HMAC-SM3值
|
|
9
|
+
*/
|
|
10
|
+
digest(message: string | Uint8Array): Uint8Array;
|
|
11
|
+
/**
|
|
12
|
+
* 计算HMAC-SM3值并返回十六进制字符串
|
|
13
|
+
*/
|
|
14
|
+
digestHex(message: string | Uint8Array): string;
|
|
15
|
+
/**
|
|
16
|
+
* 静态方法:快速计算HMAC-SM3
|
|
17
|
+
*/
|
|
18
|
+
static hmac(key: string | Uint8Array, message: string | Uint8Array): string;
|
|
19
|
+
}
|
|
20
|
+
export default HmacSM3;
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4
|
+
var __publicField = (obj, key, value) => {
|
|
5
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
6
|
+
return value;
|
|
7
|
+
};
|
|
8
|
+
const _SM3 = class {
|
|
9
|
+
static rotateLeft(x, n) {
|
|
10
|
+
return x << n | x >>> 32 - n;
|
|
11
|
+
}
|
|
12
|
+
static FFj(X, Y, Z, j) {
|
|
13
|
+
if (j >= 0 && j <= 15) {
|
|
14
|
+
return X ^ Y ^ Z;
|
|
15
|
+
} else {
|
|
16
|
+
return X & Y | X & Z | Y & Z;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
static GGj(X, Y, Z, j) {
|
|
20
|
+
if (j >= 0 && j <= 15) {
|
|
21
|
+
return X ^ Y ^ Z;
|
|
22
|
+
} else {
|
|
23
|
+
return X & Y | ~X & Z;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
static P0(X) {
|
|
27
|
+
return X ^ _SM3.rotateLeft(X, 9) ^ _SM3.rotateLeft(X, 17);
|
|
28
|
+
}
|
|
29
|
+
static P1(X) {
|
|
30
|
+
return X ^ _SM3.rotateLeft(X, 15) ^ _SM3.rotateLeft(X, 23);
|
|
31
|
+
}
|
|
32
|
+
static pad(message) {
|
|
33
|
+
const bitLength = message.length * 8;
|
|
34
|
+
const paddingLength = (448 - (bitLength + 1) % 512 + 512) % 512;
|
|
35
|
+
const totalLength = (bitLength + 1 + paddingLength + 64) / 8;
|
|
36
|
+
const padded = new Uint8Array(totalLength);
|
|
37
|
+
padded.set(message);
|
|
38
|
+
padded[message.length] = 128;
|
|
39
|
+
const lengthBytes = new Uint8Array(8);
|
|
40
|
+
const lengthView = new DataView(lengthBytes.buffer);
|
|
41
|
+
lengthView.setBigUint64(0, BigInt(bitLength), false);
|
|
42
|
+
padded.set(lengthBytes, totalLength - 8);
|
|
43
|
+
return padded;
|
|
44
|
+
}
|
|
45
|
+
static processBlock(block, state) {
|
|
46
|
+
const W = new Uint32Array(68);
|
|
47
|
+
const W1 = new Uint32Array(64);
|
|
48
|
+
for (let i = 0; i < 16; i++) {
|
|
49
|
+
const view = new DataView(block.buffer, block.byteOffset + i * 4, 4);
|
|
50
|
+
W[i] = view.getUint32(0, false);
|
|
51
|
+
}
|
|
52
|
+
for (let j = 16; j < 68; j++) {
|
|
53
|
+
W[j] = _SM3.P1(W[j - 16] ^ W[j - 9] ^ _SM3.rotateLeft(W[j - 3], 15)) ^ _SM3.rotateLeft(W[j - 13], 7) ^ W[j - 6];
|
|
54
|
+
}
|
|
55
|
+
for (let j = 0; j < 64; j++) {
|
|
56
|
+
W1[j] = W[j] ^ W[j + 4];
|
|
57
|
+
}
|
|
58
|
+
let A = state[0];
|
|
59
|
+
let B = state[1];
|
|
60
|
+
let C = state[2];
|
|
61
|
+
let D = state[3];
|
|
62
|
+
let E = state[4];
|
|
63
|
+
let F = state[5];
|
|
64
|
+
let G = state[6];
|
|
65
|
+
let H = state[7];
|
|
66
|
+
for (let j = 0; j < 64; j++) {
|
|
67
|
+
const SS1 = _SM3.rotateLeft(_SM3.rotateLeft(A, 12) + E + _SM3.rotateLeft(_SM3.T[j], j), 7);
|
|
68
|
+
const SS2 = SS1 ^ _SM3.rotateLeft(A, 12);
|
|
69
|
+
const TT1 = _SM3.FFj(A, B, C, j) + D + SS2 + W1[j];
|
|
70
|
+
const TT2 = _SM3.GGj(E, F, G, j) + H + SS1 + W[j];
|
|
71
|
+
D = C;
|
|
72
|
+
C = _SM3.rotateLeft(B, 9);
|
|
73
|
+
B = A;
|
|
74
|
+
A = TT1;
|
|
75
|
+
H = G;
|
|
76
|
+
G = _SM3.rotateLeft(F, 19);
|
|
77
|
+
F = E;
|
|
78
|
+
E = _SM3.P0(TT2);
|
|
79
|
+
}
|
|
80
|
+
state[0] ^= A;
|
|
81
|
+
state[1] ^= B;
|
|
82
|
+
state[2] ^= C;
|
|
83
|
+
state[3] ^= D;
|
|
84
|
+
state[4] ^= E;
|
|
85
|
+
state[5] ^= F;
|
|
86
|
+
state[6] ^= G;
|
|
87
|
+
state[7] ^= H;
|
|
88
|
+
}
|
|
89
|
+
static hash(message) {
|
|
90
|
+
const padded = _SM3.pad(message);
|
|
91
|
+
const state = new Uint32Array(_SM3.IV);
|
|
92
|
+
for (let i = 0; i < padded.length; i += 64) {
|
|
93
|
+
const block = padded.slice(i, i + 64);
|
|
94
|
+
_SM3.processBlock(block, state);
|
|
95
|
+
}
|
|
96
|
+
const result = new Uint8Array(32);
|
|
97
|
+
const resultView = new DataView(result.buffer);
|
|
98
|
+
for (let i = 0; i < 8; i++) {
|
|
99
|
+
resultView.setUint32(i * 4, state[i], false);
|
|
100
|
+
}
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
static hashHex(message) {
|
|
104
|
+
const msgArray = typeof message === "string" ? new TextEncoder().encode(message) : message;
|
|
105
|
+
const hashBytes = _SM3.hash(msgArray);
|
|
106
|
+
return Array.from(hashBytes).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
let SM3 = _SM3;
|
|
110
|
+
__publicField(SM3, "IV", new Uint32Array([
|
|
111
|
+
1937774191,
|
|
112
|
+
1226093241,
|
|
113
|
+
388252375,
|
|
114
|
+
3666478592,
|
|
115
|
+
2842636476,
|
|
116
|
+
372324522,
|
|
117
|
+
3817729613,
|
|
118
|
+
2969243214
|
|
119
|
+
]));
|
|
120
|
+
__publicField(SM3, "T", new Uint32Array(64));
|
|
121
|
+
(() => {
|
|
122
|
+
for (let j = 0; j < 16; j++) {
|
|
123
|
+
_SM3.T[j] = 2043430169;
|
|
124
|
+
}
|
|
125
|
+
for (let j = 16; j < 64; j++) {
|
|
126
|
+
_SM3.T[j] = 2055708042;
|
|
127
|
+
}
|
|
128
|
+
})();
|
|
129
|
+
class HmacSM3 {
|
|
130
|
+
constructor(key) {
|
|
131
|
+
__publicField(this, "key");
|
|
132
|
+
this.key = typeof key === "string" ? new TextEncoder().encode(key) : key;
|
|
133
|
+
}
|
|
134
|
+
digest(message) {
|
|
135
|
+
const msgArray = typeof message === "string" ? new TextEncoder().encode(message) : message;
|
|
136
|
+
const blockSize = 64;
|
|
137
|
+
let keyBuffer;
|
|
138
|
+
if (this.key.length > blockSize) {
|
|
139
|
+
keyBuffer = SM3.hash(this.key);
|
|
140
|
+
} else {
|
|
141
|
+
keyBuffer = new Uint8Array(blockSize);
|
|
142
|
+
keyBuffer.set(this.key);
|
|
143
|
+
for (let i = this.key.length; i < blockSize; i++) {
|
|
144
|
+
keyBuffer[i] = 0;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
const ipadKey = new Uint8Array(blockSize);
|
|
148
|
+
const opadKey = new Uint8Array(blockSize);
|
|
149
|
+
for (let i = 0; i < blockSize; i++) {
|
|
150
|
+
ipadKey[i] = keyBuffer[i] ^ 54;
|
|
151
|
+
opadKey[i] = keyBuffer[i] ^ 92;
|
|
152
|
+
}
|
|
153
|
+
const innerData = new Uint8Array(ipadKey.length + msgArray.length);
|
|
154
|
+
innerData.set(ipadKey);
|
|
155
|
+
innerData.set(msgArray, ipadKey.length);
|
|
156
|
+
const innerHash = SM3.hash(innerData);
|
|
157
|
+
const outerData = new Uint8Array(opadKey.length + innerHash.length);
|
|
158
|
+
outerData.set(opadKey);
|
|
159
|
+
outerData.set(innerHash, opadKey.length);
|
|
160
|
+
const finalHash = SM3.hash(outerData);
|
|
161
|
+
return finalHash;
|
|
162
|
+
}
|
|
163
|
+
digestHex(message) {
|
|
164
|
+
const hashBytes = this.digest(message);
|
|
165
|
+
return Array.from(hashBytes).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
166
|
+
}
|
|
167
|
+
static hmac(key, message) {
|
|
168
|
+
const hmac = new HmacSM3(key);
|
|
169
|
+
return hmac.digestHex(message);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
module.exports = HmacSM3;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "szld-libs",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.50",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"dev": "vite",
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"@types/react-dom": "^18.2.18",
|
|
29
29
|
"@types/react-resizable": "^3.0.8",
|
|
30
30
|
"@types/react-window": "^1.8.5",
|
|
31
|
+
"@types/sm-crypto": "^0.3.4",
|
|
31
32
|
"@vitejs/plugin-react": "^3.0.0",
|
|
32
33
|
"less": "^4.1.3",
|
|
33
34
|
"rimraf": "^4.1.2",
|