yuang-framework-ui-common 1.0.7 → 1.0.9
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/lib/config/http.ts +1 -0
- package/lib/utils/aesUtils.ts +50 -0
- package/lib/utils/gatewayUtils.ts +2 -1
- package/lib/utils/rsaUtils.ts +76 -0
- package/package.json +3 -1
- package/src/.DS_Store +0 -0
package/lib/config/http.ts
CHANGED
@@ -12,6 +12,7 @@ const $http = axios.create({
|
|
12
12
|
|
13
13
|
/* 请求拦截 */
|
14
14
|
$http.interceptors.request.use(config => {
|
15
|
+
config.headers["X-Requested-With"] = 'XMLHttpRequest';
|
15
16
|
|
16
17
|
let gatewayAccessToken = localStorage.getItem("gatewayAccessToken") ?? '';
|
17
18
|
let ssoAccessToken = localStorage.getItem("ssoAccessToken") ?? '';
|
@@ -0,0 +1,50 @@
|
|
1
|
+
|
2
|
+
import CryptoJS from 'crypto-js'
|
3
|
+
|
4
|
+
// aes加密
|
5
|
+
const aesEncrypt = (aesKey, originData) => {
|
6
|
+
// 设置一个默认值,如果第二个参数为空采用默认值,不为空则采用新设置的密钥
|
7
|
+
var key = CryptoJS.enc.Utf8.parse(aesKey)
|
8
|
+
var srcs = CryptoJS.enc.Utf8.parse(originData)
|
9
|
+
var encrypted = CryptoJS.AES.encrypt(srcs, key, {
|
10
|
+
// 切记 需要和后端算法模式一致
|
11
|
+
mode: CryptoJS.mode.ECB,
|
12
|
+
padding: CryptoJS.pad.Pkcs7
|
13
|
+
})
|
14
|
+
|
15
|
+
return encrypted.toString()
|
16
|
+
}
|
17
|
+
|
18
|
+
// aes解密
|
19
|
+
const aesDecrypt = (aesKey, originData) => {
|
20
|
+
var key = CryptoJS.enc.Utf8.parse(aesKey)
|
21
|
+
var decrypt = CryptoJS.AES.decrypt(originData, key, {
|
22
|
+
// 切记 需要和后端算法模式一致
|
23
|
+
mode: CryptoJS.mode.ECB,
|
24
|
+
padding: CryptoJS.pad.Pkcs7
|
25
|
+
})
|
26
|
+
return CryptoJS.enc.Utf8.stringify(decrypt).toString()
|
27
|
+
}
|
28
|
+
/**
|
29
|
+
* 获取aesKey
|
30
|
+
* 生成16位随机码
|
31
|
+
* @returns {string}
|
32
|
+
*/
|
33
|
+
const getAesKey = () => {
|
34
|
+
var chars = [ '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K', 'L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f',
|
35
|
+
'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'
|
36
|
+
]
|
37
|
+
var nums = ''
|
38
|
+
// 这个地方切记要选择16位,因为美国对密钥长度有限制,选择32位的话加解密会报错,需要根据jdk版本去修改相关jar包,有点恼火,选择16位就不用处理。
|
39
|
+
for (var i = 0; i < 16; i++) {
|
40
|
+
var id = parseInt(Math.random() * 61)
|
41
|
+
nums += chars[id]
|
42
|
+
}
|
43
|
+
return nums
|
44
|
+
}
|
45
|
+
|
46
|
+
export {
|
47
|
+
aesEncrypt,
|
48
|
+
aesDecrypt,
|
49
|
+
getAesKey
|
50
|
+
}
|
@@ -5,11 +5,12 @@ const initGateway = () => {
|
|
5
5
|
return new Promise<void>(async resolve => {
|
6
6
|
let gatewayAccessToken = localStorage.getItem("gatewayAccessToken");
|
7
7
|
if (!gatewayAccessToken) {
|
8
|
-
let res = await http.get('/server/gateway/
|
8
|
+
let res = await http.get('/server/gateway/getGatewayConfig');
|
9
9
|
if (res.data.statusCode != 200) {
|
10
10
|
return console.error(res.data.message);
|
11
11
|
}
|
12
12
|
localStorage.setItem("gatewayAccessToken", res.data.data.gatewayAccessToken);
|
13
|
+
localStorage.setItem("gatewayPublicKey", res.data.data.gatewayPublicKey);
|
13
14
|
}
|
14
15
|
resolve();
|
15
16
|
})
|
@@ -0,0 +1,76 @@
|
|
1
|
+
|
2
|
+
import JSEncrypt from 'jsencrypt'
|
3
|
+
|
4
|
+
// rsa加密
|
5
|
+
const rsaEncrypt = (Str, afterPublicKey) => {
|
6
|
+
const encryptor = new JSEncrypt()
|
7
|
+
encryptor.setPublicKey(afterPublicKey) // 设置公钥
|
8
|
+
return encryptor.encrypt(Str) // 对数据进行加密
|
9
|
+
}
|
10
|
+
|
11
|
+
// rsa解密
|
12
|
+
const rsaDecrypt = (Str, frontPrivateKey) => {
|
13
|
+
const encryptor = new JSEncrypt()
|
14
|
+
encryptor.setPrivateKey(frontPrivateKey) // 设置私钥
|
15
|
+
return encryptor.decrypt(Str) // 对数据进行解密
|
16
|
+
}
|
17
|
+
|
18
|
+
//获取rsa密钥对
|
19
|
+
const getRsaKeys = () => {
|
20
|
+
return new Promise((resolve, reject) => {
|
21
|
+
window.crypto.subtle
|
22
|
+
.generateKey(
|
23
|
+
{
|
24
|
+
name: 'RSA-OAEP',
|
25
|
+
modulusLength: 2048, //can be 1024, 2048, or 4096
|
26
|
+
publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
|
27
|
+
hash: { name: 'SHA-512' } //can be "SHA-1", "SHA-256", "SHA-384", or "SHA-512"
|
28
|
+
},
|
29
|
+
true, //whether the key is extractable (i.e. can be used in exportKey)
|
30
|
+
['encrypt', 'decrypt'] //must be ["encrypt", "decrypt"] or ["wrapKey", "unwrapKey"]
|
31
|
+
)
|
32
|
+
.then(function(key) {
|
33
|
+
window.crypto.subtle
|
34
|
+
.exportKey('pkcs8', key.privateKey)
|
35
|
+
.then(function(keydata1) {
|
36
|
+
window.crypto.subtle
|
37
|
+
.exportKey('spki', key.publicKey)
|
38
|
+
.then(function(keydata2) {
|
39
|
+
var privateKey = convertText(keydata1, 1)
|
40
|
+
|
41
|
+
var publicKey = convertText(keydata2)
|
42
|
+
|
43
|
+
resolve({ privateKey, publicKey })
|
44
|
+
})
|
45
|
+
.catch(function(err) {
|
46
|
+
reject(err)
|
47
|
+
})
|
48
|
+
})
|
49
|
+
.catch(function(err) {
|
50
|
+
reject(err)
|
51
|
+
})
|
52
|
+
})
|
53
|
+
.catch(function(err) {
|
54
|
+
reject(err)
|
55
|
+
})
|
56
|
+
})
|
57
|
+
}
|
58
|
+
const convertText = (buffer, isPrivate = 0) => {
|
59
|
+
var binary = ''
|
60
|
+
var bytes = new Uint8Array(buffer)
|
61
|
+
var len = bytes.byteLength
|
62
|
+
for (var i = 0; i < len; i++) {
|
63
|
+
binary += String.fromCharCode(bytes[i])
|
64
|
+
}
|
65
|
+
var base64 = window.btoa(binary)
|
66
|
+
|
67
|
+
let text = base64.replace(/[^\x00-\xff]/g, '$&\x01').replace(/.{64}\x01?/g, '$&\n')
|
68
|
+
|
69
|
+
return text
|
70
|
+
}
|
71
|
+
|
72
|
+
export {
|
73
|
+
rsaEncrypt,
|
74
|
+
rsaDecrypt,
|
75
|
+
getRsaKeys
|
76
|
+
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "yuang-framework-ui-common",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.9",
|
4
4
|
"private": false,
|
5
5
|
"type": "module",
|
6
6
|
"scripts": {
|
@@ -27,8 +27,10 @@
|
|
27
27
|
"@wangeditor/editor": "^5.1.23",
|
28
28
|
"@wangeditor/editor-for-vue": "^5.1.12",
|
29
29
|
"axios": "^1.7.3",
|
30
|
+
"crypto-js": "^4.2.0",
|
30
31
|
"element-plus": "^2.7.8",
|
31
32
|
"js-cookie": "^3.0.5",
|
33
|
+
"jsencrypt": "^3.3.2",
|
32
34
|
"moment": "^2.30.1",
|
33
35
|
"pinia": "^2.1.7",
|
34
36
|
"vue": "^3.4.29",
|
package/src/.DS_Store
ADDED
Binary file
|