mirror of
https://github.com/jumpserver/lina.git
synced 2025-09-24 04:33:06 +00:00
perf: 优化加密
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
"axios": "0.21.1",
|
||||
"axios-retry": "^3.1.9",
|
||||
"cron-parser": "^4.0.0",
|
||||
"crypto-js": "^4.1.1",
|
||||
"deepmerge": "^4.2.2",
|
||||
"echarts": "^4.7.0",
|
||||
"element-ui": "2.13.2",
|
||||
|
38
src/utils/crypto.js
Normal file
38
src/utils/crypto.js
Normal file
@@ -0,0 +1,38 @@
|
||||
import { JSEncrypt } from 'jsencrypt'
|
||||
import CryptoJS from 'crypto-js'
|
||||
|
||||
export function fillKey(key) {
|
||||
let keySize = 128
|
||||
// 如果超过 key 16 位, 最大取 32 位,需要更改填充
|
||||
if (key.length > 16) {
|
||||
key = key.slice(0, 32)
|
||||
keySize = keySize * 2
|
||||
}
|
||||
key = key.slice(0, keySize)
|
||||
const filledKey = Buffer.alloc(keySize / 8)
|
||||
const keys = Buffer.from(key)
|
||||
if (keys.length < filledKey.length) {
|
||||
for (let i = 0; i < filledKey.length; i++) {
|
||||
filledKey[i] = keys[i]
|
||||
}
|
||||
} else {
|
||||
return keys
|
||||
}
|
||||
}
|
||||
|
||||
export function aesEncrypt(text, originKey) {
|
||||
const key = CryptoJS.enc.Utf8.parse(fillKey(originKey))
|
||||
return CryptoJS.AES.encrypt(text, key, {
|
||||
mode: CryptoJS.mode.ECB,
|
||||
padding: CryptoJS.pad.ZeroPadding
|
||||
}).toString()
|
||||
}
|
||||
|
||||
export function rsaEncrypt(text, pubKey) {
|
||||
const jsEncrypt = new JSEncrypt()
|
||||
jsEncrypt.setPublicKey(pubKey)
|
||||
return jsEncrypt.encrypt(text)
|
||||
}
|
||||
|
||||
window.aesEncrypt = aesEncrypt
|
||||
|
@@ -3194,6 +3194,11 @@ crypto-browserify@^3.11.0:
|
||||
randombytes "^2.0.0"
|
||||
randomfill "^1.0.3"
|
||||
|
||||
crypto-js@^4.1.1:
|
||||
version "4.1.1"
|
||||
resolved "https://registry.npmmirror.com/crypto-js/-/crypto-js-4.1.1.tgz#9e485bcf03521041bd85844786b83fb7619736cf"
|
||||
integrity sha512-o2JlM7ydqd3Qk9CA0L4NL6mTzU2sdx96a+oOfPu8Mkl/PK51vSyoi8/rQ8NknZtk44vq15lmhAj9CIAGwgeWKw==
|
||||
|
||||
css-color-names@0.0.4, css-color-names@^0.0.4:
|
||||
version "0.0.4"
|
||||
resolved "https://registry.yarnpkg.com/css-color-names/-/css-color-names-0.0.4.tgz#808adc2e79cf84738069b646cb20ec27beb629e0"
|
||||
|
Reference in New Issue
Block a user