@lingxiteam/ebe-utils 0.0.33 → 0.0.35
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/es/index.d.ts +5 -1
- package/es/index.js +107 -62
- package/lib/h5public/src/components/factory/src/Icon/IconED/index.less +43 -0
- package/lib/h5public/src/components/factory/src/Icon/IconED/index.tsx +290 -0
- package/lib/public/src/services/api/engine.ts +0 -2
- package/lib/public/src/utils/Security/clientCapabilities.ts +8 -0
- package/lib/public/src/utils/Security/config.ts +56 -49
- package/lib/public/src/utils/Security/const.ts +38 -127
- package/lib/public/src/utils/Security/debug/data.ts +86 -0
- package/lib/public/src/utils/Security/debug/index.ts +21 -0
- package/lib/public/src/utils/Security/encipher/sign.ts +25 -56
- package/lib/public/src/utils/Security/html.ts +52 -0
- package/lib/public/src/utils/Security/httpEncryption.ts +42 -23
- package/lib/public/src/utils/Security/index.ts +15 -7
- package/lib/public/src/utils/Security/requester/fetch.ts +87 -52
- package/lib/public/src/utils/Security/requester/wx.ts +60 -11
- package/lib/public/src/utils/Security/requester/xhr.ts +194 -40
- package/lib/public/src/utils/Security/types.ts +8 -90
- package/lib/public/src/utils/Security/urlEncryption.ts +108 -0
- package/lib/public/src/utils/Security/utils/atob.ts +34 -0
- package/lib/public/src/utils/Security/utils/caseInsensitive.ts +25 -0
- package/lib/public/src/utils/Security/utils/check.ts +27 -3
- package/lib/public/src/utils/Security/utils/cookie.ts +101 -53
- package/lib/public/src/utils/Security/utils/encrypted.ts +190 -43
- package/lib/public/src/utils/Security/utils/random.ts +21 -0
- package/lib/public/src/utils/Security/utils/storge.ts +22 -0
- package/lib/public/src/utils/Security/utils/url.ts +30 -5
- package/lib/public/src/utils/getSceneCode.ts +51 -0
- package/lib/public/src/utils/useTool.ts +2 -172
- package/lib/public/yarn.lock +11441 -0
- package/package.json +3 -3
- package/lib/pcpublic/src/components/pcfactory/src/StdUpload/assets/closeIcon.png +0 -0
- package/lib/pcpublic/src/components/pcfactory/src/StdUpload/assets/fileName.png +0 -0
- package/lib/pcpublic/src/components/pcfactory/src/StdUpload/assets/img.png +0 -0
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import capabilities from '../clientCapabilities';
|
|
2
2
|
import config from '../config';
|
|
3
|
+
import { reqIdKey } from '../const';
|
|
4
|
+
import debug from '../debug';
|
|
3
5
|
import { createHttpSignStr } from '../encipher/sign';
|
|
6
|
+
import { getObjectValue } from '../utils/caseInsensitive';
|
|
4
7
|
import {
|
|
5
8
|
checkIsEncryption,
|
|
6
9
|
checkIsSignMode,
|
|
@@ -8,6 +11,7 @@ import {
|
|
|
8
11
|
checkIsUrlIgnore,
|
|
9
12
|
} from '../utils/check';
|
|
10
13
|
import { decryptedStr, encryptedRequestParams } from '../utils/encrypted';
|
|
14
|
+
import { addUrlParameters } from '../utils/url';
|
|
11
15
|
|
|
12
16
|
const originRequester: any = capabilities.wxRequest ? wx.request : undefined;
|
|
13
17
|
|
|
@@ -27,6 +31,18 @@ const wxRequest = (
|
|
|
27
31
|
}
|
|
28
32
|
|
|
29
33
|
let requester;
|
|
34
|
+
|
|
35
|
+
// 记录原始请求数据,数据调试时查看
|
|
36
|
+
const originRequestData = opts.data;
|
|
37
|
+
|
|
38
|
+
// wx直接在控制台输入变量访问的是window下的变量,但js执行写入的变量在global,需特殊处理debugId
|
|
39
|
+
const debugId = `global.${debug?.createId()}`;
|
|
40
|
+
if (debugId) {
|
|
41
|
+
opts.header
|
|
42
|
+
? (opts.header[reqIdKey] = debugId)
|
|
43
|
+
: (opts.header = { [reqIdKey]: debugId });
|
|
44
|
+
}
|
|
45
|
+
|
|
30
46
|
// 请求头配置
|
|
31
47
|
// headers.disabledSignKey 关闭签名(兼容,新模式通过将 securityHeaderKey设为false关闭)
|
|
32
48
|
// headers.disabledEncrypted 关闭加密(兼容,新模式通过将 securityHeaderKey设为false关闭)
|
|
@@ -37,17 +53,22 @@ const wxRequest = (
|
|
|
37
53
|
// 优先使用当前请求头指定的安全模式
|
|
38
54
|
const finallyMode = modeInHeadParam || config.mode;
|
|
39
55
|
|
|
40
|
-
// 拦截success,处理解密
|
|
56
|
+
// 拦截success、fail,处理解密
|
|
41
57
|
const originSuccess = opts.success;
|
|
42
58
|
if (originSuccess) {
|
|
43
59
|
const success: WechatMiniprogram.RequestSuccessCallback = (response) => {
|
|
44
|
-
|
|
60
|
+
// wxrequest没有提供像 Headers.get 和 xhr.getResponseHeader 获取请求头信息(对大小写不敏感), 故此处需通过工具函数获取
|
|
61
|
+
const securityType = getObjectValue(response.header, securityHeaderKey);
|
|
45
62
|
if (checkIsEncryption(securityType)) {
|
|
46
63
|
let result;
|
|
47
64
|
try {
|
|
48
65
|
if (typeof response.data === 'string') {
|
|
49
|
-
result = decryptedStr(response.data, securityType
|
|
50
|
-
if (
|
|
66
|
+
result = decryptedStr(response.data, securityType);
|
|
67
|
+
if (
|
|
68
|
+
getObjectValue(response.header, 'Content-Type').indexOf(
|
|
69
|
+
'application/json',
|
|
70
|
+
) !== -1
|
|
71
|
+
) {
|
|
51
72
|
result = JSON.parse(result);
|
|
52
73
|
}
|
|
53
74
|
}
|
|
@@ -55,6 +76,11 @@ const wxRequest = (
|
|
|
55
76
|
response.data =
|
|
56
77
|
typeof result === 'undefined' ? response.data : result;
|
|
57
78
|
}
|
|
79
|
+
// 记录响应debug信息
|
|
80
|
+
if (debugId) {
|
|
81
|
+
debug?.store(debugId, 'modeResponse', securityType);
|
|
82
|
+
debug?.store(debugId, 'response', result);
|
|
83
|
+
}
|
|
58
84
|
}
|
|
59
85
|
originSuccess(response);
|
|
60
86
|
};
|
|
@@ -81,11 +107,23 @@ const wxRequest = (
|
|
|
81
107
|
opts.header = {
|
|
82
108
|
...(opts.header || {}),
|
|
83
109
|
[securityHeaderKey]: finallyMode,
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
110
|
+
// 当get请求时,会将data拼装在url上,签名时需对url处理
|
|
111
|
+
[signValueKeyName]:
|
|
112
|
+
opts.method?.toLowerCase() === 'get' &&
|
|
113
|
+
Object.prototype.toString.call(opts.data) === '[object Object]'
|
|
114
|
+
? createHttpSignStr(
|
|
115
|
+
addUrlParameters(
|
|
116
|
+
opts.url,
|
|
117
|
+
opts.data as WechatMiniprogram.IAnyObject,
|
|
118
|
+
),
|
|
119
|
+
{ method: opts.method, body: undefined, headers: opts.header },
|
|
120
|
+
finallyMode,
|
|
121
|
+
)
|
|
122
|
+
: createHttpSignStr(
|
|
123
|
+
opts.url,
|
|
124
|
+
{ method: opts.method, body: opts.data, headers: opts.header },
|
|
125
|
+
finallyMode,
|
|
126
|
+
),
|
|
89
127
|
};
|
|
90
128
|
// 后端根据cookie里的值进行校验
|
|
91
129
|
if (checkIsSignWithSalt(finallyMode)) {
|
|
@@ -103,8 +141,12 @@ const wxRequest = (
|
|
|
103
141
|
// search和body加密
|
|
104
142
|
const [encryptedUrl, encryptedOpts] = encryptedRequestParams(
|
|
105
143
|
opts.url,
|
|
106
|
-
{
|
|
144
|
+
{
|
|
145
|
+
body: opts.data,
|
|
146
|
+
headers: { method: opts.method, ...(opts.header || {}) },
|
|
147
|
+
},
|
|
107
148
|
finallyMode,
|
|
149
|
+
'wxRequest',
|
|
108
150
|
);
|
|
109
151
|
opts.url = encryptedUrl;
|
|
110
152
|
if (encryptedOpts.body) {
|
|
@@ -113,12 +155,19 @@ const wxRequest = (
|
|
|
113
155
|
if (encryptedOpts.headers) {
|
|
114
156
|
opts.header = encryptedOpts.headers;
|
|
115
157
|
}
|
|
116
|
-
requester = originRequester(
|
|
158
|
+
requester = originRequester(opts);
|
|
117
159
|
} else {
|
|
118
160
|
// 其他
|
|
119
161
|
requester = originRequester(opts);
|
|
120
162
|
}
|
|
121
163
|
|
|
164
|
+
// 记录请求debug信息
|
|
165
|
+
if (debugId) {
|
|
166
|
+
debug?.store(debugId, 'modeRequest', finallyMode);
|
|
167
|
+
debug?.store(debugId, 'url', opts.url);
|
|
168
|
+
debug?.store(debugId, 'param', originRequestData);
|
|
169
|
+
}
|
|
170
|
+
|
|
122
171
|
return requester;
|
|
123
172
|
};
|
|
124
173
|
|
|
@@ -1,11 +1,16 @@
|
|
|
1
|
+
import capabilities from '../clientCapabilities';
|
|
1
2
|
import config from '../config';
|
|
2
|
-
|
|
3
|
+
import { commonGlobal, reqIdKey } from '../const';
|
|
4
|
+
import debug from '../debug';
|
|
3
5
|
import { createHttpSignStr } from '../encipher/sign';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
import {
|
|
7
|
+
checkIsEncryption,
|
|
8
|
+
checkIsSignMode,
|
|
9
|
+
checkIsUrlIgnore,
|
|
10
|
+
} from '../utils/check';
|
|
11
|
+
import { decryptedStr, encryptedRequestParams } from '../utils/encrypted';
|
|
7
12
|
|
|
8
|
-
const
|
|
13
|
+
const OriginRequester: any = capabilities.xhr ? XMLHttpRequest : undefined;
|
|
9
14
|
|
|
10
15
|
// 从请求头中获取参数
|
|
11
16
|
function getRequestHeaders(xhr: XMLHttpRequest) {
|
|
@@ -14,15 +19,16 @@ function getRequestHeaders(xhr: XMLHttpRequest) {
|
|
|
14
19
|
.getAllResponseHeaders()
|
|
15
20
|
.split('\n')
|
|
16
21
|
.forEach((header) => {
|
|
17
|
-
|
|
18
|
-
|
|
22
|
+
if (header) {
|
|
23
|
+
const [key, value] = header.split(': ');
|
|
24
|
+
headers[key] = value;
|
|
25
|
+
}
|
|
19
26
|
});
|
|
20
27
|
return headers;
|
|
21
28
|
}
|
|
22
29
|
|
|
23
30
|
const xhr = function () {
|
|
24
|
-
|
|
25
|
-
const originXhr = new originRequester();
|
|
31
|
+
const instanceXhr = new OriginRequester();
|
|
26
32
|
|
|
27
33
|
const securityHeaderKey = config.securityHeaderKey as string;
|
|
28
34
|
const signValueKeyName = config.sign?.valueKeyName as string;
|
|
@@ -30,13 +36,16 @@ const xhr = function () {
|
|
|
30
36
|
let finallyMode: any = config.mode;
|
|
31
37
|
let xhrUrl: string = '';
|
|
32
38
|
let xhrMethod: any = '';
|
|
39
|
+
const openOptions: any = {};
|
|
33
40
|
|
|
34
41
|
// 用于存储请求头信息
|
|
35
42
|
const requestHeaders: any = {};
|
|
36
43
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
44
|
+
const debugId = debug?.createId();
|
|
45
|
+
|
|
46
|
+
// 劫持: open 方法, 记录url、请求头等信息
|
|
47
|
+
const originalOpen = instanceXhr.open;
|
|
48
|
+
instanceXhr.open = function (
|
|
40
49
|
method: string,
|
|
41
50
|
url: string,
|
|
42
51
|
async?: boolean,
|
|
@@ -46,16 +55,26 @@ const xhr = function () {
|
|
|
46
55
|
// 记录url地址
|
|
47
56
|
xhrUrl = url;
|
|
48
57
|
xhrMethod = method;
|
|
58
|
+
openOptions.async = async;
|
|
59
|
+
openOptions.user = user;
|
|
60
|
+
openOptions.password = password;
|
|
49
61
|
// 获取请求头中的参数
|
|
50
|
-
const _requestHeaders = getRequestHeaders(
|
|
62
|
+
const _requestHeaders = getRequestHeaders(instanceXhr);
|
|
51
63
|
Object.assign(requestHeaders, _requestHeaders);
|
|
52
|
-
// 调用原始的 open
|
|
53
|
-
originalOpen.call(
|
|
64
|
+
// 调用原始的 open 方法(async不能为undefined,不然引起调用报错)
|
|
65
|
+
originalOpen.call(
|
|
66
|
+
this,
|
|
67
|
+
method,
|
|
68
|
+
url,
|
|
69
|
+
typeof async === 'undefined' ? true : async,
|
|
70
|
+
user,
|
|
71
|
+
password,
|
|
72
|
+
);
|
|
54
73
|
};
|
|
55
74
|
|
|
56
|
-
//
|
|
57
|
-
const originalSetRequestHeader =
|
|
58
|
-
|
|
75
|
+
// 劫持: setRequestHeader 方法,记录请求头信息
|
|
76
|
+
const originalSetRequestHeader = instanceXhr.setRequestHeader;
|
|
77
|
+
instanceXhr.setRequestHeader = function (
|
|
59
78
|
key: string,
|
|
60
79
|
value: string | number | boolean,
|
|
61
80
|
) {
|
|
@@ -66,9 +85,10 @@ const xhr = function () {
|
|
|
66
85
|
originalSetRequestHeader.call(this, key, value);
|
|
67
86
|
};
|
|
68
87
|
|
|
69
|
-
//
|
|
70
|
-
const originalSend =
|
|
71
|
-
|
|
88
|
+
// 劫持: send 方法,进行签名或加密处理
|
|
89
|
+
const originalSend = instanceXhr.send;
|
|
90
|
+
|
|
91
|
+
instanceXhr.send = function (data: any) {
|
|
72
92
|
// 判定是否符合忽略规则
|
|
73
93
|
if (
|
|
74
94
|
checkIsUrlIgnore(xhrUrl, {
|
|
@@ -81,41 +101,175 @@ const xhr = function () {
|
|
|
81
101
|
return;
|
|
82
102
|
}
|
|
83
103
|
|
|
84
|
-
//
|
|
85
|
-
|
|
104
|
+
// 加密后的请求数据(加密模式下保存的加密数据)
|
|
105
|
+
let encryptedData: any;
|
|
86
106
|
|
|
87
107
|
// 优先使用请求头自带的模式
|
|
88
|
-
if (
|
|
89
|
-
finallyMode =
|
|
108
|
+
if (requestHeaders[securityHeaderKey]) {
|
|
109
|
+
finallyMode = requestHeaders[securityHeaderKey];
|
|
90
110
|
}
|
|
91
111
|
|
|
92
|
-
//
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
112
|
+
// 请求头上添加安全模式标识
|
|
113
|
+
this.setRequestHeader(securityHeaderKey, finallyMode);
|
|
114
|
+
|
|
115
|
+
// 请求头上添加debug标识
|
|
116
|
+
if (debugId) {
|
|
117
|
+
this.setRequestHeader(reqIdKey, debugId);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (checkIsSignMode(finallyMode)) {
|
|
121
|
+
// 签名并添加额外的参数
|
|
122
|
+
originalSetRequestHeader.call(
|
|
123
|
+
this,
|
|
124
|
+
signValueKeyName,
|
|
125
|
+
createHttpSignStr(
|
|
126
|
+
xhrUrl,
|
|
127
|
+
{ method: xhrMethod, headers: requestHeaders, body: data },
|
|
128
|
+
finallyMode,
|
|
129
|
+
),
|
|
130
|
+
);
|
|
131
|
+
} else if (checkIsEncryption(finallyMode)) {
|
|
132
|
+
// 加密处理
|
|
133
|
+
const [encryptedUrl, encryptedOpts] = encryptedRequestParams(
|
|
98
134
|
xhrUrl,
|
|
99
|
-
{
|
|
135
|
+
{ headers: requestHeaders, body: data },
|
|
100
136
|
finallyMode,
|
|
101
|
-
|
|
102
|
-
|
|
137
|
+
'xhr',
|
|
138
|
+
);
|
|
139
|
+
// 如果url参数加密了,则重新open一个新地址
|
|
140
|
+
if (encryptedUrl !== xhrUrl) {
|
|
141
|
+
originalOpen.call(
|
|
142
|
+
this,
|
|
143
|
+
xhrMethod,
|
|
144
|
+
encryptedUrl,
|
|
145
|
+
typeof openOptions.async === 'undefined' ? true : openOptions.async,
|
|
146
|
+
openOptions.user,
|
|
147
|
+
openOptions.password,
|
|
148
|
+
);
|
|
149
|
+
// 重新设置header上的字段
|
|
150
|
+
Object.keys(requestHeaders).forEach((key) => {
|
|
151
|
+
originalSetRequestHeader.call(this, key, requestHeaders[key]);
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
encryptedData = encryptedOpts.body;
|
|
155
|
+
}
|
|
103
156
|
|
|
104
|
-
//
|
|
105
|
-
|
|
157
|
+
// 记录请求debug信息
|
|
158
|
+
if (debugId) {
|
|
159
|
+
debug?.store(debugId, 'modeRequest', finallyMode);
|
|
160
|
+
debug?.store(debugId, 'url', xhrUrl);
|
|
161
|
+
debug?.store(debugId, 'param', data);
|
|
162
|
+
}
|
|
106
163
|
|
|
107
164
|
// 调用原始的 send 方法
|
|
108
|
-
originalSend.call(this, data);
|
|
165
|
+
originalSend.call(this, encryptedData || data);
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
// 劫持: 获取response内容,响应解密处理
|
|
169
|
+
const stashResponse: Record<string, any> = {};
|
|
170
|
+
let onreadystatechange: Function;
|
|
171
|
+
const getEncryptionResponseContent = (
|
|
172
|
+
_xhr: XMLHttpRequest,
|
|
173
|
+
key: 'response' | 'responseText' | 'responseXML',
|
|
174
|
+
securityType: any,
|
|
175
|
+
) => {
|
|
176
|
+
if (typeof stashResponse[key] === 'string') {
|
|
177
|
+
return decryptedStr(stashResponse[key], securityType);
|
|
178
|
+
}
|
|
179
|
+
return stashResponse[key];
|
|
109
180
|
};
|
|
181
|
+
instanceXhr.onreadystatechange = function () {
|
|
182
|
+
if (instanceXhr.readyState === 4) {
|
|
183
|
+
// getResponseHeader方法标头名称的搜索不区分大小写
|
|
184
|
+
const securityType = instanceXhr.getResponseHeader(securityHeaderKey);
|
|
185
|
+
// 如果是需要解密,则劫持response
|
|
186
|
+
if (securityType && checkIsEncryption(securityType)) {
|
|
187
|
+
// 记录原Response内容
|
|
188
|
+
stashResponse.response = instanceXhr.response;
|
|
189
|
+
stashResponse.responseText = instanceXhr.responseText;
|
|
190
|
+
stashResponse.responseXML = instanceXhr.responseXML;
|
|
110
191
|
|
|
111
|
-
|
|
192
|
+
// 记录响应debug信息
|
|
193
|
+
if (debugId && debug) {
|
|
194
|
+
const content = getEncryptionResponseContent(
|
|
195
|
+
instanceXhr,
|
|
196
|
+
'response',
|
|
197
|
+
securityType,
|
|
198
|
+
);
|
|
199
|
+
let finallyResponse: any;
|
|
200
|
+
try {
|
|
201
|
+
finallyResponse = JSON.parse(content);
|
|
202
|
+
} catch (e) {
|
|
203
|
+
finallyResponse = content;
|
|
204
|
+
}
|
|
205
|
+
debug.store(debugId, 'modeResponse', securityType);
|
|
206
|
+
debug.store(debugId, 'response', finallyResponse);
|
|
207
|
+
}
|
|
208
|
+
// 劫持Response getter进行解密
|
|
209
|
+
Object.defineProperties(instanceXhr, {
|
|
210
|
+
response: {
|
|
211
|
+
get() {
|
|
212
|
+
return getEncryptionResponseContent(
|
|
213
|
+
this,
|
|
214
|
+
'response',
|
|
215
|
+
securityType,
|
|
216
|
+
);
|
|
217
|
+
},
|
|
218
|
+
configurable: true,
|
|
219
|
+
enumerable: false,
|
|
220
|
+
},
|
|
221
|
+
responseText: {
|
|
222
|
+
get() {
|
|
223
|
+
return getEncryptionResponseContent(
|
|
224
|
+
this,
|
|
225
|
+
'responseText',
|
|
226
|
+
securityType,
|
|
227
|
+
);
|
|
228
|
+
},
|
|
229
|
+
configurable: true,
|
|
230
|
+
enumerable: false,
|
|
231
|
+
},
|
|
232
|
+
responseXML: {
|
|
233
|
+
get() {
|
|
234
|
+
return getEncryptionResponseContent(
|
|
235
|
+
this,
|
|
236
|
+
'responseXML',
|
|
237
|
+
securityType,
|
|
238
|
+
);
|
|
239
|
+
},
|
|
240
|
+
configurable: true,
|
|
241
|
+
enumerable: false,
|
|
242
|
+
},
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
if (typeof onreadystatechange === 'function') {
|
|
247
|
+
onreadystatechange.call(this);
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
Object.defineProperties(instanceXhr, {
|
|
252
|
+
onreadystatechange: {
|
|
253
|
+
set(value) {
|
|
254
|
+
onreadystatechange = value;
|
|
255
|
+
},
|
|
256
|
+
configurable: true,
|
|
257
|
+
enumerable: false,
|
|
258
|
+
},
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
// 处理完毕,返回xhr实例
|
|
262
|
+
return instanceXhr;
|
|
112
263
|
};
|
|
113
264
|
|
|
265
|
+
// 标记劫持的XMLHttpRequest
|
|
266
|
+
xhr.isLxSecurity = true;
|
|
267
|
+
|
|
114
268
|
export const conflict = () => {
|
|
115
|
-
|
|
269
|
+
commonGlobal.XMLHttpRequest = xhr;
|
|
116
270
|
};
|
|
117
271
|
export const noConflict = () => {
|
|
118
|
-
|
|
272
|
+
commonGlobal.XMLHttpRequest = OriginRequester;
|
|
119
273
|
};
|
|
120
274
|
|
|
121
275
|
export default xhr;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
type requester = 'fetch' | 'xhr' | 'wxRequest';
|
|
1
|
+
export type requester = 'fetch' | 'xhr' | 'wxRequest';
|
|
2
2
|
|
|
3
3
|
export const enum MODE {
|
|
4
|
-
// 参数签名(旧数据)
|
|
5
|
-
SIGN_KEY = 'signKey',
|
|
6
4
|
// 参数签名
|
|
7
5
|
SIGN = '1.0',
|
|
8
6
|
// 时间限制性签名
|
|
@@ -17,21 +15,17 @@ export const enum MODE {
|
|
|
17
15
|
RSA = '2.0',
|
|
18
16
|
// AES参数加密
|
|
19
17
|
AES = '3.0',
|
|
20
|
-
// DES参数加密
|
|
21
|
-
DES = '4.0',
|
|
22
18
|
}
|
|
23
19
|
|
|
20
|
+
export type modeType = `${(typeof MODE)[keyof typeof MODE]}`;
|
|
21
|
+
|
|
24
22
|
// 自定义加解密函数
|
|
25
23
|
type EncryptionFunctionType = (
|
|
26
24
|
content: string,
|
|
27
25
|
key: string,
|
|
28
|
-
CryptoJS:
|
|
26
|
+
CryptoJS: any,
|
|
29
27
|
) => string;
|
|
30
28
|
|
|
31
|
-
export type fnDESEncryptType = EncryptionFunctionType;
|
|
32
|
-
|
|
33
|
-
export type fnDESDecryptType = EncryptionFunctionType;
|
|
34
|
-
|
|
35
29
|
export type fnAESEncryptType = EncryptionFunctionType;
|
|
36
30
|
|
|
37
31
|
export type fnAESDecryptType = EncryptionFunctionType;
|
|
@@ -39,13 +33,13 @@ export type fnAESDecryptType = EncryptionFunctionType;
|
|
|
39
33
|
export type fnRSAEncryptType = (
|
|
40
34
|
content: string,
|
|
41
35
|
publicKey: string,
|
|
42
|
-
JSEncrypt:
|
|
36
|
+
JSEncrypt: any,
|
|
43
37
|
) => string;
|
|
44
38
|
|
|
45
39
|
export type fnRSADecryptType = (
|
|
46
40
|
content: string,
|
|
47
41
|
privKey: string,
|
|
48
|
-
JSEncrypt:
|
|
42
|
+
JSEncrypt: any,
|
|
49
43
|
) => string;
|
|
50
44
|
|
|
51
45
|
export declare namespace encipherOptionType {
|
|
@@ -54,7 +48,7 @@ export declare namespace encipherOptionType {
|
|
|
54
48
|
saltKey?: string;
|
|
55
49
|
saltValue?: string | Function;
|
|
56
50
|
valueKeyName?: string;
|
|
57
|
-
|
|
51
|
+
headerKeys?: string[];
|
|
58
52
|
}
|
|
59
53
|
interface aes {
|
|
60
54
|
key?: string;
|
|
@@ -62,12 +56,6 @@ export declare namespace encipherOptionType {
|
|
|
62
56
|
decrypt?: fnAESDecryptType;
|
|
63
57
|
}
|
|
64
58
|
|
|
65
|
-
interface des {
|
|
66
|
-
key?: string;
|
|
67
|
-
encrypt?: fnDESEncryptType;
|
|
68
|
-
decrypt?: fnDESDecryptType;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
59
|
interface rsa {
|
|
72
60
|
privKey?: string;
|
|
73
61
|
publicKey?: string;
|
|
@@ -78,13 +66,12 @@ export declare namespace encipherOptionType {
|
|
|
78
66
|
|
|
79
67
|
type ignoreSupportType = string | RegExp | Function;
|
|
80
68
|
export interface configType {
|
|
81
|
-
mode?:
|
|
69
|
+
mode?: modeType;
|
|
82
70
|
securityHeaderKey?: string;
|
|
83
71
|
requester?: requester | requester[];
|
|
84
72
|
ignore?: ignoreSupportType | ignoreSupportType[];
|
|
85
73
|
sign?: encipherOptionType.sign;
|
|
86
74
|
aes?: encipherOptionType.aes;
|
|
87
|
-
des?: encipherOptionType.des;
|
|
88
75
|
rsa?: encipherOptionType.rsa;
|
|
89
76
|
timeDeviation?: number;
|
|
90
77
|
debug?: boolean;
|
|
@@ -108,72 +95,3 @@ export interface signHttpOptionsType {
|
|
|
108
95
|
search?: string | any;
|
|
109
96
|
saltValue?: string;
|
|
110
97
|
}
|
|
111
|
-
|
|
112
|
-
namespace securityType {
|
|
113
|
-
export interface httpEncryption {
|
|
114
|
-
start: (startConfig?: configType) => void;
|
|
115
|
-
stop: () => void;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export function createHttpSignStr(
|
|
119
|
-
url: string,
|
|
120
|
-
options: signHttpOptionsType,
|
|
121
|
-
version?: any,
|
|
122
|
-
): string;
|
|
123
|
-
|
|
124
|
-
export function createHttpSignWithUrl(
|
|
125
|
-
url: string,
|
|
126
|
-
options?: signHttpOptionsType,
|
|
127
|
-
version?: any,
|
|
128
|
-
): string;
|
|
129
|
-
|
|
130
|
-
export function RSAEncrypt(
|
|
131
|
-
content: string,
|
|
132
|
-
publicKey: string,
|
|
133
|
-
handle?: fnRSAEncryptType,
|
|
134
|
-
): string;
|
|
135
|
-
|
|
136
|
-
export function RSADecrypt(
|
|
137
|
-
content: string,
|
|
138
|
-
privKey: string,
|
|
139
|
-
handle?: fnRSADecryptType,
|
|
140
|
-
): string;
|
|
141
|
-
|
|
142
|
-
export function AESEncrypt(
|
|
143
|
-
content: string,
|
|
144
|
-
aesKey: string,
|
|
145
|
-
handle?: fnAESEncryptType,
|
|
146
|
-
): string;
|
|
147
|
-
|
|
148
|
-
export function AESDecrypt(
|
|
149
|
-
content: string,
|
|
150
|
-
aesKey: string,
|
|
151
|
-
handle?: fnAESDecryptType,
|
|
152
|
-
): string;
|
|
153
|
-
|
|
154
|
-
export function DESEncrypt(
|
|
155
|
-
content: string,
|
|
156
|
-
desKey: string,
|
|
157
|
-
handle?: fnDESEncryptType,
|
|
158
|
-
): string;
|
|
159
|
-
|
|
160
|
-
export function DESDecrypt(
|
|
161
|
-
content: string,
|
|
162
|
-
desKey: string,
|
|
163
|
-
handle?: fnDESDecryptType,
|
|
164
|
-
): string;
|
|
165
|
-
|
|
166
|
-
export function setConfig(config: configType): void;
|
|
167
|
-
|
|
168
|
-
export function lxEncrypt(str: string): string;
|
|
169
|
-
|
|
170
|
-
export type httpEncryptionConfigType = typeof configType;
|
|
171
|
-
|
|
172
|
-
export type KEYS = {
|
|
173
|
-
signKey: string;
|
|
174
|
-
rsaPublicKey: string;
|
|
175
|
-
rsaPrivKey: string;
|
|
176
|
-
aesKey: string;
|
|
177
|
-
desKey: string;
|
|
178
|
-
};
|
|
179
|
-
}
|