mirror of
https://github.com/jumpserver/lina.git
synced 2025-09-19 17:54:37 +00:00
perf: aes key 强制最大 16
This commit is contained in:
@@ -3,17 +3,11 @@ import CryptoJS from 'crypto-js'
|
|||||||
import VueCookie from 'vue-cookie'
|
import VueCookie from 'vue-cookie'
|
||||||
|
|
||||||
export function fillKey(key) {
|
export function fillKey(key) {
|
||||||
let keySize = 128
|
const KeyLength = 16
|
||||||
// 如果超过 key 16 位, 最大取 32 位,需要更改填充
|
if (key.length > KeyLength) {
|
||||||
if (key.length > 16) {
|
key = key.slice(0, KeyLength)
|
||||||
key = key.slice(0, 32)
|
|
||||||
keySize = keySize * 2
|
|
||||||
}
|
}
|
||||||
const filledKeyLength = keySize / 8
|
const filledKey = Buffer.alloc(KeyLength)
|
||||||
if (key.length >= filledKeyLength) {
|
|
||||||
return key.slice(0, filledKeyLength)
|
|
||||||
}
|
|
||||||
const filledKey = Buffer.alloc(keySize / 8)
|
|
||||||
const keys = Buffer.from(key)
|
const keys = Buffer.from(key)
|
||||||
for (let i = 0; i < keys.length; i++) {
|
for (let i = 0; i < keys.length; i++) {
|
||||||
filledKey[i] = keys[i]
|
filledKey[i] = keys[i]
|
||||||
@@ -54,4 +48,5 @@ export function encryptPassword(password) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
window.aesEncrypt = aesEncrypt
|
window.aesEncrypt = aesEncrypt
|
||||||
|
window.fillKey = fillKey
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user