@pubinfo/module-crypto 2.1.1
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/LICENSE +21 -0
- package/dist/api/modules/crypto/index.d.ts +1 -0
- package/dist/api/modules/crypto/pubSysConfigController.d.ts +22 -0
- package/dist/api/request.d.ts +1 -0
- package/dist/apiContext.d.ts +2 -0
- package/dist/context.d.ts +10 -0
- package/dist/cryptoAlg/aes.d.ts +4 -0
- package/dist/cryptoAlg/rsa.d.ts +1 -0
- package/dist/cryptoAlg/sm4-cbc.d.ts +4 -0
- package/dist/cryptoAlg/sm4-ecb.d.ts +4 -0
- package/dist/cryptoSetting.d.ts +6 -0
- package/dist/drawerCryptoUrl-pN2BPC_q.js +4 -0
- package/dist/drawerCryptoUrl.vue_vue_type_script_setup_true_lang-CztdWly1.js +136 -0
- package/dist/helper.d.ts +3 -0
- package/dist/index.css +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +9003 -0
- package/dist/interface.d.ts +18 -0
- package/dist/pages/enum.d.ts +7 -0
- package/dist/setting-2FfcqVsW.js +267 -0
- package/dist/setting.css +1 -0
- package/package.json +47 -0
- package/src/api/modules/crypto/index.ts +1 -0
- package/src/api/modules/crypto/pubSysConfigController.ts +52 -0
- package/src/api/modules/crypto/typings.d.ts +49 -0
- package/src/api/request.ts +4 -0
- package/src/apiContext.ts +4 -0
- package/src/assets/images/crypto-setting-bg.png +0 -0
- package/src/context.ts +12 -0
- package/src/cryptoAlg/aes.ts +52 -0
- package/src/cryptoAlg/rsa.ts +13 -0
- package/src/cryptoAlg/sm4-cbc.ts +49 -0
- package/src/cryptoAlg/sm4-ecb.ts +46 -0
- package/src/cryptoSetting.ts +67 -0
- package/src/helper.ts +21 -0
- package/src/index.ts +65 -0
- package/src/interface.ts +21 -0
- package/src/pages/components/drawerCryptoUrl.vue +116 -0
- package/src/pages/enum.ts +7 -0
- package/src/pages/setting.vue +273 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { RequestInstance } from 'pubinfo';
|
|
2
|
+
export interface CryptoOptions {
|
|
3
|
+
/**
|
|
4
|
+
* 接口请求实例
|
|
5
|
+
*/
|
|
6
|
+
request: InternalContext['request'];
|
|
7
|
+
cryptoSetting: cryptoInternal;
|
|
8
|
+
}
|
|
9
|
+
export interface cryptoInternal {
|
|
10
|
+
name: string;
|
|
11
|
+
encrypt: (text: string) => Promise<string>;
|
|
12
|
+
decrypt: (text: string) => Promise<string>;
|
|
13
|
+
header?: Record<string, string>;
|
|
14
|
+
}
|
|
15
|
+
export interface InternalContext {
|
|
16
|
+
request: RequestInstance;
|
|
17
|
+
}
|
|
18
|
+
export { RequestInstance };
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import { Form as G, FormItem as J, Switch as Q, CheckableTag as q, Space as H, Button as K } from "ant-design-vue/es";
|
|
2
|
+
import { useAuth as X, PubinfoIcon as Y } from "pubinfo";
|
|
3
|
+
import { QuestionCircleOutlined as Z, PlusCircleOutlined as ee } from "@ant-design/icons-vue";
|
|
4
|
+
import { defineComponent as te, ref as k, reactive as oe, onMounted as se, resolveDirective as ae, createElementBlock as E, openBlock as u, createElementVNode as d, createVNode as a, withCtx as l, unref as s, normalizeClass as V, createTextVNode as h, createBlock as P, createCommentVNode as re, withDirectives as D, toDisplayString as L } from "vue";
|
|
5
|
+
import { ProTable as ne } from "@pubinfo/pro-components";
|
|
6
|
+
import { message as ie, Modal as le } from "ant-design-vue";
|
|
7
|
+
import { g as ce, p as de, c as B } from "./index.js";
|
|
8
|
+
import { u as pe, _ as fe } from "./drawerCryptoUrl.vue_vue_type_script_setup_true_lang-CztdWly1.js";
|
|
9
|
+
import './setting.css';var n = /* @__PURE__ */ ((r) => (r.ADD = "新增", r.EDIT = "编辑", r.REMOVE = "删除", r.ENABLE = "启用", r.DISABLE = "停用", r))(n || {});
|
|
10
|
+
const ue = {
|
|
11
|
+
"w-full": "",
|
|
12
|
+
"h-full": "",
|
|
13
|
+
"pt-10px": "",
|
|
14
|
+
"px-10px": "",
|
|
15
|
+
"overflow-auto": ""
|
|
16
|
+
}, me = {
|
|
17
|
+
"h-full": "",
|
|
18
|
+
"min-w-1130px": ""
|
|
19
|
+
}, _e = { class: "pt-20px pl-20px h-161px flex flex-col bg-[#ffffff] box-border bg-[url('@/assets/images/crypto-setting-bg.png')] bg-cover text-[#4e5969] dark:text-[#C9CDD4]" }, he = { class: "flex items-center" }, ye = { class: "p-5px bg-[#f2f3f5] rounded-5px flex items-center" }, xe = { class: "flex items-center ml-15px text-[#a3a4a8]" }, be = { class: "h-[calc(100%-165px)]" }, Ce = ["onClick"], ge = { class: "ml-4px" }, ve = ["onClick"], we = { class: "ml-4px" }, ke = /* @__PURE__ */ te({
|
|
20
|
+
__name: "setting",
|
|
21
|
+
setup(r) {
|
|
22
|
+
const y = k(), p = k(), f = k(), x = { style: { width: "auto" } }, O = { span: 24 }, { auth: T } = X(), o = oe({
|
|
23
|
+
isCrypto: !0,
|
|
24
|
+
mode: !0,
|
|
25
|
+
whiteListUrls: []
|
|
26
|
+
}), [i, b] = pe(!1);
|
|
27
|
+
se(I);
|
|
28
|
+
async function I() {
|
|
29
|
+
await ce().then((t) => {
|
|
30
|
+
b(!1), t && t.data && t.success && (o.isCrypto = t.data.cryptoEnabled || !1, o.whiteListUrls = t.data.cryptoWhitePath, o.mode = t.data.cryptoMode === void 0 ? !0 : t.data.cryptoMode);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
function R(t, e) {
|
|
34
|
+
e && (o.mode = t, C());
|
|
35
|
+
}
|
|
36
|
+
async function C() {
|
|
37
|
+
if (!i.value) {
|
|
38
|
+
b(!0);
|
|
39
|
+
try {
|
|
40
|
+
await p.value?.validate();
|
|
41
|
+
const {
|
|
42
|
+
isCrypto: t,
|
|
43
|
+
mode: e,
|
|
44
|
+
whiteListUrls: v
|
|
45
|
+
} = o, m = {
|
|
46
|
+
cryptoEnabled: t,
|
|
47
|
+
cryptoMode: e,
|
|
48
|
+
cryptoWhitePath: v
|
|
49
|
+
}, { success: _ } = await de({ json: JSON.stringify(m) });
|
|
50
|
+
_ && (ie.success("配置更改成功"), B.callAsync({ ...B.use(), isCrypto: o.isCrypto, cryptoMode: o.mode, whiteListUrls: o.whiteListUrls }, () => {
|
|
51
|
+
I();
|
|
52
|
+
}));
|
|
53
|
+
} catch {
|
|
54
|
+
b(!1);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const A = [
|
|
59
|
+
{
|
|
60
|
+
minWidth: 60,
|
|
61
|
+
hideInTable: !1,
|
|
62
|
+
title: "url地址",
|
|
63
|
+
dataIndex: "url"
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
hideInSearch: !0,
|
|
67
|
+
minWidth: 200,
|
|
68
|
+
title: "描述",
|
|
69
|
+
dataIndex: "description",
|
|
70
|
+
ellipsis: !0
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
hideInSearch: !0,
|
|
74
|
+
title: "操作",
|
|
75
|
+
dataIndex: "action",
|
|
76
|
+
width: 200,
|
|
77
|
+
fixed: "right",
|
|
78
|
+
hideInTable() {
|
|
79
|
+
return !T([
|
|
80
|
+
"crypto_url_add",
|
|
81
|
+
"crypto_url_edit",
|
|
82
|
+
"crypto_url_delete"
|
|
83
|
+
]);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
];
|
|
87
|
+
function g(t, e) {
|
|
88
|
+
if (!i.value)
|
|
89
|
+
switch (t) {
|
|
90
|
+
case n.ADD:
|
|
91
|
+
f.value.open(!1, o.whiteListUrls);
|
|
92
|
+
break;
|
|
93
|
+
case n.EDIT:
|
|
94
|
+
f.value.open(!0, o.whiteListUrls, e);
|
|
95
|
+
break;
|
|
96
|
+
case n.REMOVE:
|
|
97
|
+
W(o.whiteListUrls || [], e || 0);
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function W(t, e) {
|
|
102
|
+
le.confirm({
|
|
103
|
+
title: "删除",
|
|
104
|
+
content: "确定要删除该条数据吗?",
|
|
105
|
+
async onOk() {
|
|
106
|
+
t.splice(e, 1), U(t);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
function U(t) {
|
|
111
|
+
o.whiteListUrls = t, C();
|
|
112
|
+
}
|
|
113
|
+
return (t, e) => {
|
|
114
|
+
const v = Q, m = J, _ = q, $ = G, F = ee, N = K, M = Y, j = H, w = ae("auth");
|
|
115
|
+
return u(), E("div", ue, [
|
|
116
|
+
d("div", me, [
|
|
117
|
+
d("div", _e, [
|
|
118
|
+
a($, {
|
|
119
|
+
ref_key: "formRef",
|
|
120
|
+
ref: p,
|
|
121
|
+
model: o,
|
|
122
|
+
"label-col": x,
|
|
123
|
+
"wrapper-col": O,
|
|
124
|
+
class: "safe-rule-form"
|
|
125
|
+
}, {
|
|
126
|
+
default: l(() => [
|
|
127
|
+
a(m, {
|
|
128
|
+
label: "开启加密",
|
|
129
|
+
name: "isCrypto"
|
|
130
|
+
}, {
|
|
131
|
+
default: l(() => [
|
|
132
|
+
a(v, {
|
|
133
|
+
checked: o.isCrypto,
|
|
134
|
+
"onUpdate:checked": e[0] || (e[0] = (c) => o.isCrypto = c),
|
|
135
|
+
disabled: s(i),
|
|
136
|
+
onChange: C
|
|
137
|
+
}, null, 8, ["checked", "disabled"])
|
|
138
|
+
]),
|
|
139
|
+
_: 1
|
|
140
|
+
}),
|
|
141
|
+
a(m, {
|
|
142
|
+
label: "模式",
|
|
143
|
+
name: "isCrypto"
|
|
144
|
+
}, {
|
|
145
|
+
default: l(() => [
|
|
146
|
+
d("div", he, [
|
|
147
|
+
d("div", ye, [
|
|
148
|
+
a(_, {
|
|
149
|
+
checked: o.mode,
|
|
150
|
+
disabled: s(i),
|
|
151
|
+
class: V(s(i) ? "cursor-not-allowed!" : ""),
|
|
152
|
+
onChange: e[1] || (e[1] = (c) => !s(i) && R(!0, c))
|
|
153
|
+
}, {
|
|
154
|
+
default: l(() => e[4] || (e[4] = [
|
|
155
|
+
h(" 白名单 ")
|
|
156
|
+
])),
|
|
157
|
+
_: 1,
|
|
158
|
+
__: [4]
|
|
159
|
+
}, 8, ["checked", "disabled", "class"]),
|
|
160
|
+
a(_, {
|
|
161
|
+
checked: !o.mode,
|
|
162
|
+
class: V(["mr-0px!", s(i) ? "cursor-not-allowed!" : ""]),
|
|
163
|
+
onChange: e[2] || (e[2] = (c) => !s(i) && R(!1, c))
|
|
164
|
+
}, {
|
|
165
|
+
default: l(() => e[5] || (e[5] = [
|
|
166
|
+
h(" 黑名单 ")
|
|
167
|
+
])),
|
|
168
|
+
_: 1,
|
|
169
|
+
__: [5]
|
|
170
|
+
}, 8, ["checked", "class"])
|
|
171
|
+
]),
|
|
172
|
+
d("div", xe, [
|
|
173
|
+
a(s(Z), { class: "mr-5px" }),
|
|
174
|
+
e[6] || (e[6] = h("白名单模式下,仅不加密过滤列表中的接口;黑名单模式下,仅加密过滤列表中的接口。 "))
|
|
175
|
+
])
|
|
176
|
+
])
|
|
177
|
+
]),
|
|
178
|
+
_: 1
|
|
179
|
+
})
|
|
180
|
+
]),
|
|
181
|
+
_: 1
|
|
182
|
+
}, 8, ["model"])
|
|
183
|
+
]),
|
|
184
|
+
d("div", be, [
|
|
185
|
+
a(s(ne), {
|
|
186
|
+
ref_key: "tableRef",
|
|
187
|
+
ref: y,
|
|
188
|
+
"row-key": "id",
|
|
189
|
+
"data-source": o.whiteListUrls,
|
|
190
|
+
columns: A,
|
|
191
|
+
"auto-height": "",
|
|
192
|
+
search: !1,
|
|
193
|
+
pagination: !1,
|
|
194
|
+
scroll: { x: 1e3 }
|
|
195
|
+
}, {
|
|
196
|
+
toolbar: l(() => [
|
|
197
|
+
D((u(), P(N, {
|
|
198
|
+
type: "primary",
|
|
199
|
+
disabled: s(i),
|
|
200
|
+
onClick: e[3] || (e[3] = (c) => g(s(n).ADD))
|
|
201
|
+
}, {
|
|
202
|
+
default: l(() => [
|
|
203
|
+
a(F),
|
|
204
|
+
h(" " + L(s(n).ADD), 1)
|
|
205
|
+
]),
|
|
206
|
+
_: 1
|
|
207
|
+
}, 8, ["disabled"])), [
|
|
208
|
+
[w, "crypto_url_add"]
|
|
209
|
+
])
|
|
210
|
+
]),
|
|
211
|
+
bodyCell: l(({ column: c, index: S }) => [
|
|
212
|
+
c.dataIndex === "action" ? (u(), P(j, { key: 0 }, {
|
|
213
|
+
default: l(() => [
|
|
214
|
+
D((u(), E("a", {
|
|
215
|
+
class: "flex items-center hover:opacity-80",
|
|
216
|
+
onClick: (z) => g(s(n).EDIT, S)
|
|
217
|
+
}, [
|
|
218
|
+
a(M, {
|
|
219
|
+
name: "edit",
|
|
220
|
+
class: "text-base"
|
|
221
|
+
}),
|
|
222
|
+
d("span", ge, L(s(n).EDIT), 1)
|
|
223
|
+
], 8, Ce)), [
|
|
224
|
+
[w, "crypto_url_edit"]
|
|
225
|
+
]),
|
|
226
|
+
D((u(), E("span", {
|
|
227
|
+
flex: "",
|
|
228
|
+
"items-center": "",
|
|
229
|
+
"text-red-500": "",
|
|
230
|
+
"hover:cursor-pointer": "",
|
|
231
|
+
"hover:text-red-500": "",
|
|
232
|
+
"hover:opacity-80": "",
|
|
233
|
+
onClick: (z) => g(s(n).REMOVE, S)
|
|
234
|
+
}, [
|
|
235
|
+
a(M, {
|
|
236
|
+
name: "remove",
|
|
237
|
+
class: "text-base"
|
|
238
|
+
}),
|
|
239
|
+
d("span", we, L(s(n).REMOVE), 1)
|
|
240
|
+
], 8, ve)), [
|
|
241
|
+
[w, "crypto_url_delete"]
|
|
242
|
+
])
|
|
243
|
+
]),
|
|
244
|
+
_: 2
|
|
245
|
+
}, 1024)) : re("", !0)
|
|
246
|
+
]),
|
|
247
|
+
_: 1
|
|
248
|
+
}, 8, ["data-source"])
|
|
249
|
+
])
|
|
250
|
+
]),
|
|
251
|
+
a(fe, {
|
|
252
|
+
ref_key: "drawerRef",
|
|
253
|
+
ref: f,
|
|
254
|
+
onSubmit: U
|
|
255
|
+
}, null, 512)
|
|
256
|
+
]);
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
}), Ee = (r, y) => {
|
|
260
|
+
const p = r.__vccOpts || r;
|
|
261
|
+
for (const [f, x] of y)
|
|
262
|
+
p[f] = x;
|
|
263
|
+
return p;
|
|
264
|
+
}, Pe = /* @__PURE__ */ Ee(ke, [["__scopeId", "data-v-89197708"]]);
|
|
265
|
+
export {
|
|
266
|
+
Pe as default
|
|
267
|
+
};
|
package/dist/setting.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.safe-rule-form .ant-input[data-v-89197708],.safe-rule-form .ant-select[data-v-89197708]{width:90%}.safe-rule-form[data-v-89197708] .ant-tag-checkable-checked{background:#fff;color:#1677ff;font-size:13px}.safe-rule-form[data-v-89197708] .ant-tag-checkable{font-size:13px}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pubinfo/module-crypto",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "2.1.1",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": {
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"default": "./dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"./style.css": "./dist/index.css"
|
|
11
|
+
},
|
|
12
|
+
"main": "./dist/index.js",
|
|
13
|
+
"module": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"src"
|
|
18
|
+
],
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": "^20.19.0 || >=22.12.0"
|
|
21
|
+
},
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"@ant-design/icons-vue": "^7.0.1",
|
|
24
|
+
"@pubinfo/pro-components": "^1.8.0",
|
|
25
|
+
"ant-design-vue": "^4.2.6",
|
|
26
|
+
"pubinfo": "2.1.1"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@vueuse/core": "^13.7.0",
|
|
30
|
+
"crypto-js": "^4.2.0",
|
|
31
|
+
"gm-crypto": "^0.1.12",
|
|
32
|
+
"jsencrypt": "^3.3.2"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@ant-design/icons-vue": "^7.0.1",
|
|
36
|
+
"@pubinfo/pro-components": "^1.8.0",
|
|
37
|
+
"@types/crypto-js": "^4.2.2",
|
|
38
|
+
"ant-design-vue": "^4.2.6",
|
|
39
|
+
"pubinfo": "2.1.1"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"dev": "pubinfo build -w --sourcemap",
|
|
43
|
+
"build": "pubinfo build",
|
|
44
|
+
"openapi": "pnpx @pubinfo/openapi generate",
|
|
45
|
+
"test": "vitest"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './pubSysConfigController';
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { basic as request } from '@/api/request';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @description 编辑加解密配置
|
|
5
|
+
* @url /crypto/editCryptoConfig
|
|
6
|
+
* @method POST
|
|
7
|
+
* @author @pubinfo/openapi
|
|
8
|
+
*/
|
|
9
|
+
export function postCryptoEditCryptoConfig<
|
|
10
|
+
R = API.ResponseDataBoolean,
|
|
11
|
+
T = API.ResponseDataBoolean,
|
|
12
|
+
>(
|
|
13
|
+
body: API.EditCryptoConfigDto,
|
|
14
|
+
options?: Parameters<typeof request.Post<R, T>>[2],
|
|
15
|
+
) {
|
|
16
|
+
return request.Post<R, T>('/crypto/editCryptoConfig', body, {
|
|
17
|
+
headers: {
|
|
18
|
+
'Content-Type': 'application/json',
|
|
19
|
+
},
|
|
20
|
+
...(options || {}),
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @description 获取加解密配置
|
|
26
|
+
* @url /crypto/getCryptoConfig
|
|
27
|
+
* @method GET
|
|
28
|
+
* @author @pubinfo/openapi
|
|
29
|
+
*/
|
|
30
|
+
export function getCryptoGetCryptoConfig<
|
|
31
|
+
R = API.ResponseDataCryptoConfig,
|
|
32
|
+
T = API.ResponseDataCryptoConfig,
|
|
33
|
+
>(options?: Parameters<typeof request.Get<R, T>>[1]) {
|
|
34
|
+
return request.Get<R, T>('/crypto/getCryptoConfig', {
|
|
35
|
+
...(options || {}),
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @description 获取公钥及加解密配置
|
|
41
|
+
* @url /crypto/getPublicKeyAndConfig
|
|
42
|
+
* @method GET
|
|
43
|
+
* @author @pubinfo/openapi
|
|
44
|
+
*/
|
|
45
|
+
export function getCryptoGetPublicKeyAndConfig<
|
|
46
|
+
R = API.ResponseDataCryptoConfigExt,
|
|
47
|
+
T = API.ResponseDataCryptoConfigExt,
|
|
48
|
+
>(options?: Parameters<typeof request.Get<R, T>>[1]) {
|
|
49
|
+
return request.Get<R, T>('/crypto/getPublicKeyAndConfig', {
|
|
50
|
+
...(options || {}),
|
|
51
|
+
});
|
|
52
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
declare namespace API {
|
|
4
|
+
type CryptoConfig = {
|
|
5
|
+
cryptoEnabled?: boolean;
|
|
6
|
+
cryptoMode?: boolean;
|
|
7
|
+
cryptoWhitePath?: UrlEntry[];
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
type CryptoConfigExt = {
|
|
11
|
+
cryptoEnabled?: boolean;
|
|
12
|
+
cryptoMode?: boolean;
|
|
13
|
+
cryptoWhitePath?: UrlEntry[];
|
|
14
|
+
publicKey?: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
type EditCryptoConfigDto = {
|
|
18
|
+
json?: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
type ResponseDataBoolean = {
|
|
22
|
+
code?: number;
|
|
23
|
+
msg?: string;
|
|
24
|
+
hint?: string;
|
|
25
|
+
data?: boolean;
|
|
26
|
+
success?: boolean;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
type ResponseDataCryptoConfig = {
|
|
30
|
+
code?: number;
|
|
31
|
+
msg?: string;
|
|
32
|
+
hint?: string;
|
|
33
|
+
data?: CryptoConfig;
|
|
34
|
+
success?: boolean;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
type ResponseDataCryptoConfigExt = {
|
|
38
|
+
code?: number;
|
|
39
|
+
msg?: string;
|
|
40
|
+
hint?: string;
|
|
41
|
+
data?: CryptoConfigExt;
|
|
42
|
+
success?: boolean;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
type UrlEntry = {
|
|
46
|
+
url?: string;
|
|
47
|
+
description?: string;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
Binary file
|
package/src/context.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { cryptoInternal } from './interface';
|
|
2
|
+
import { createContext } from 'pubinfo';
|
|
3
|
+
|
|
4
|
+
export const ctx = createContext<{
|
|
5
|
+
isCrypto: boolean
|
|
6
|
+
cryptoSetting: cryptoInternal
|
|
7
|
+
whiteListUrls?: API.UrlEntry[]
|
|
8
|
+
publicKey?: string
|
|
9
|
+
key?: string
|
|
10
|
+
cryptoMode: boolean
|
|
11
|
+
iv?: string
|
|
12
|
+
}>('crypto');
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { cryptoInternal } from '@/interface';
|
|
2
|
+
import CryptoJS from 'crypto-js';
|
|
3
|
+
import { ctx } from '../context';
|
|
4
|
+
|
|
5
|
+
// aes加密
|
|
6
|
+
export function aesEncrypt(plainText: string): Promise<string> {
|
|
7
|
+
return new Promise((resolve) => {
|
|
8
|
+
const AES_KEY = ctx.use().key || 'chartext12345677';
|
|
9
|
+
const encrypted = CryptoJS.AES.encrypt(
|
|
10
|
+
plainText,
|
|
11
|
+
CryptoJS.enc.Utf8.parse(AES_KEY),
|
|
12
|
+
{
|
|
13
|
+
mode: CryptoJS.mode.ECB,
|
|
14
|
+
padding: CryptoJS.pad.Pkcs7,
|
|
15
|
+
},
|
|
16
|
+
);
|
|
17
|
+
resolve(encrypted.toString().replaceAll(/\+/g, '-').replaceAll(/\//g, '_').replaceAll(/=/g, ''));
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// aes解密
|
|
22
|
+
export function aesDecrypt(cipherText: string): Promise<string> {
|
|
23
|
+
return new Promise((resolve) => {
|
|
24
|
+
const AES_KEY = ctx.use().key || 'chartext12345677';
|
|
25
|
+
let cipherTextC = cipherText.replaceAll(/-/g, '+').replaceAll(/_/g, '/');
|
|
26
|
+
while (cipherTextC.length % 4) {
|
|
27
|
+
cipherTextC += '=';
|
|
28
|
+
}
|
|
29
|
+
const decrypted = CryptoJS.AES.decrypt(
|
|
30
|
+
cipherTextC,
|
|
31
|
+
CryptoJS.enc.Utf8.parse(AES_KEY),
|
|
32
|
+
{
|
|
33
|
+
mode: CryptoJS.mode.ECB,
|
|
34
|
+
padding: CryptoJS.pad.Pkcs7,
|
|
35
|
+
},
|
|
36
|
+
);
|
|
37
|
+
try {
|
|
38
|
+
resolve(JSON.parse(decrypted.toString(CryptoJS.enc.Utf8)));
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
resolve(decrypted.toString(CryptoJS.enc.Utf8));
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function setupAes(): cryptoInternal {
|
|
47
|
+
return {
|
|
48
|
+
name: 'aes',
|
|
49
|
+
encrypt: aesEncrypt,
|
|
50
|
+
decrypt: aesDecrypt,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import JSEncrypt from 'jsencrypt';
|
|
2
|
+
import { ctx } from '../context';
|
|
3
|
+
|
|
4
|
+
// rsa加密
|
|
5
|
+
export function rsaEncrypt(plainText: string): Promise<string> {
|
|
6
|
+
return new Promise((resolve) => {
|
|
7
|
+
const KEY = ctx.use().publicKey;
|
|
8
|
+
const encrypt = new JSEncrypt();
|
|
9
|
+
encrypt.setPublicKey(`-----BEGIN PUBLIC KEY-----\n${KEY}\n-----END PUBLIC KEY-----`);
|
|
10
|
+
|
|
11
|
+
resolve(KEY ? (encrypt.encrypt(plainText) || '') : plainText);
|
|
12
|
+
});
|
|
13
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { cryptoInternal } from '@/interface';
|
|
2
|
+
import { SM4 } from 'gm-crypto';
|
|
3
|
+
import { ctx } from '../context';
|
|
4
|
+
|
|
5
|
+
// sm4加密
|
|
6
|
+
export function sm4CBCEncrypt(plainText: string): Promise<string> {
|
|
7
|
+
return new Promise((resolve) => {
|
|
8
|
+
const KEY = ctx.use().key || '0123456789abcdeffedcba9876543210';
|
|
9
|
+
const iv = ctx.use().iv || '0123456789abcdeffedcba9876543210';
|
|
10
|
+
const encryptedData = SM4.encrypt(plainText, KEY.toLowerCase(), {
|
|
11
|
+
iv,
|
|
12
|
+
mode: SM4.constants.CBC,
|
|
13
|
+
inputEncoding: 'utf8',
|
|
14
|
+
outputEncoding: 'base64',
|
|
15
|
+
});
|
|
16
|
+
resolve(encryptedData.replaceAll(/\+/g, '-').replaceAll(/\//g, '_').replaceAll(/=/g, ''));
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// sm4解密
|
|
21
|
+
export function sm4CBCDecrypt(cipherText: string): Promise<string> {
|
|
22
|
+
return new Promise((resolve) => {
|
|
23
|
+
const KEY = ctx.use().key || '0123456789abcdeffedcba9876543210';
|
|
24
|
+
const iv = ctx.use().iv || '0123456789abcdeffedcba9876543210';
|
|
25
|
+
let cipherTextC = cipherText.replaceAll(/-/g, '+').replaceAll(/_/g, '/');
|
|
26
|
+
while (cipherTextC.length % 4) {
|
|
27
|
+
cipherTextC += '=';
|
|
28
|
+
}
|
|
29
|
+
const decryptedData = SM4.decrypt(cipherTextC, KEY.toLowerCase(), {
|
|
30
|
+
iv,
|
|
31
|
+
mode: SM4.constants.CBC,
|
|
32
|
+
inputEncoding: 'base64',
|
|
33
|
+
outputEncoding: 'utf8',
|
|
34
|
+
});
|
|
35
|
+
try {
|
|
36
|
+
resolve(JSON.parse(decryptedData));
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
resolve(decryptedData);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
export function setupSm4Cbc(): cryptoInternal {
|
|
44
|
+
return {
|
|
45
|
+
name: 'sm4-cbc',
|
|
46
|
+
encrypt: sm4CBCEncrypt,
|
|
47
|
+
decrypt: sm4CBCDecrypt,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { cryptoInternal } from '@/interface';
|
|
2
|
+
import { SM4 } from 'gm-crypto';
|
|
3
|
+
import { ctx } from '../context';
|
|
4
|
+
|
|
5
|
+
// sm4加密
|
|
6
|
+
export function sm4ECBEncrypt(plainText: string): Promise<string> {
|
|
7
|
+
return new Promise((resolve) => {
|
|
8
|
+
const KEY = ctx.use().key || '0123456789abcdeffedcba9876543210';
|
|
9
|
+
const encryptedData = SM4.encrypt(plainText, KEY.toLowerCase(), {
|
|
10
|
+
mode: SM4.constants.ECB,
|
|
11
|
+
inputEncoding: 'utf8',
|
|
12
|
+
outputEncoding: 'base64',
|
|
13
|
+
});
|
|
14
|
+
resolve(encryptedData.replaceAll(/\+/g, '-').replaceAll(/\//g, '_').replaceAll(/=/g, ''));
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// sm4解密
|
|
19
|
+
export function sm4ECBDecrypt(cipherText: string): Promise<string> {
|
|
20
|
+
return new Promise((resolve) => {
|
|
21
|
+
const KEY = ctx.use().key || '0123456789abcdeffedcba9876543210';
|
|
22
|
+
let cipherTextC = cipherText.replaceAll(/-/g, '+').replaceAll(/_/g, '/');
|
|
23
|
+
while (cipherTextC.length % 4) {
|
|
24
|
+
cipherTextC += '=';
|
|
25
|
+
}
|
|
26
|
+
const decryptedData = SM4.decrypt(cipherTextC, KEY.toLowerCase(), {
|
|
27
|
+
mode: SM4.constants.ECB,
|
|
28
|
+
inputEncoding: 'base64',
|
|
29
|
+
outputEncoding: 'utf8',
|
|
30
|
+
});
|
|
31
|
+
try {
|
|
32
|
+
resolve(JSON.parse(decryptedData));
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
resolve(decryptedData);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function setupSm4Ecb(): cryptoInternal {
|
|
41
|
+
return {
|
|
42
|
+
name: 'sm4-ecb',
|
|
43
|
+
encrypt: sm4ECBEncrypt,
|
|
44
|
+
decrypt: sm4ECBDecrypt,
|
|
45
|
+
};
|
|
46
|
+
}
|