mirror of
https://github.com/jumpserver/lina.git
synced 2025-09-18 16:32:28 +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'
|
||||
|
||||
export function fillKey(key) {
|
||||
let keySize = 128
|
||||
// 如果超过 key 16 位, 最大取 32 位,需要更改填充
|
||||
if (key.length > 16) {
|
||||
key = key.slice(0, 32)
|
||||
keySize = keySize * 2
|
||||
const KeyLength = 16
|
||||
if (key.length > KeyLength) {
|
||||
key = key.slice(0, KeyLength)
|
||||
}
|
||||
const filledKeyLength = keySize / 8
|
||||
if (key.length >= filledKeyLength) {
|
||||
return key.slice(0, filledKeyLength)
|
||||
}
|
||||
const filledKey = Buffer.alloc(keySize / 8)
|
||||
const filledKey = Buffer.alloc(KeyLength)
|
||||
const keys = Buffer.from(key)
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
filledKey[i] = keys[i]
|
||||
@@ -54,4 +48,5 @@ export function encryptPassword(password) {
|
||||
}
|
||||
|
||||
window.aesEncrypt = aesEncrypt
|
||||
window.fillKey = fillKey
|
||||
|
||||
|
Reference in New Issue
Block a user