From 68c2cd6097fa61e111374e03db33db9d3e3d788b Mon Sep 17 00:00:00 2001 From: binbin_pan Date: Wed, 22 May 2024 15:20:05 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=94=A8=E6=88=B7=E5=AF=86=E7=A0=81?= =?UTF-8?q?=E6=98=8E=E6=96=87=E4=BC=A0=E8=BE=93=E6=BC=8F=E6=B4=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sgzb-ui/src/store/modules/user.js | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/sgzb-ui/src/store/modules/user.js b/sgzb-ui/src/store/modules/user.js index 75583aef..5f33664a 100644 --- a/sgzb-ui/src/store/modules/user.js +++ b/sgzb-ui/src/store/modules/user.js @@ -1,6 +1,33 @@ import { login, logout, getInfo, refreshToken,checkCode,loginByMall } from '@/api/login' import { getToken, setToken, setExpiresIn, removeToken } from '@/utils/auth' import { Notification, MessageBox, Message, Loading } from 'element-ui' + +const secretKey = 'CCCQrpassWordKey' + +async function encryptData(data, keyStr) { + const keyUint8 = new TextEncoder().encode(keyStr); + const key = await crypto.subtle.importKey( + 'raw', + keyUint8, + { name: 'AES-CBC', length: 256 }, + false, + ['encrypt'] + ); + + const iv = crypto.getRandomValues(new Uint8Array(16)); + const cipherTextBuffer = await crypto.subtle.encrypt( + { name: 'AES-CBC', iv }, + key, + new TextEncoder().encode(data) + ); + + const combined = new Uint8Array(iv.length + cipherTextBuffer.byteLength); + combined.set(iv, 0); + combined.set(new Uint8Array(cipherTextBuffer), iv.length); + + return btoa(String.fromCharCode.apply(null, combined)); +} + const user = { state: { token: getToken(), @@ -37,9 +64,9 @@ const user = { actions: { // 登录 - Login({ commit }, userInfo) { + async Login({ commit }, userInfo) { const username = userInfo.username.trim() - const password = userInfo.password + const password = await encryptData(userInfo.password, secretKey) const code = userInfo.code const uuid = userInfo.uuid return new Promise((resolve, reject) => {