From c6d4e9f55157ef5270b021b3eee998f95dd1ed6b Mon Sep 17 00:00:00 2001 From: binbin_pan Date: Fri, 24 May 2024 13:28:51 +0800 Subject: [PATCH] =?UTF-8?q?nx=E6=9A=82=E4=B8=8D=E4=BD=BF=E7=94=A8=E5=8A=A0?= =?UTF-8?q?=E5=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sgzb-ui/src/store/modules/user.js | 51 ++++++++++++++++++------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/sgzb-ui/src/store/modules/user.js b/sgzb-ui/src/store/modules/user.js index a76ad179..80636b98 100644 --- a/sgzb-ui/src/store/modules/user.js +++ b/sgzb-ui/src/store/modules/user.js @@ -5,27 +5,33 @@ import { Notification, MessageBox, Message, Loading } from 'element-ui' const secretKey = 'CCNXrpassWordKey' 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)); + try { + 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)); + + } catch (error) { + console.log('🚀 ~ 加密失败 ~ error:', error); + + } } const user = { @@ -66,7 +72,8 @@ const user = { // 登录 async Login({ commit }, userInfo) { const username = userInfo.username.trim() - const password = await encryptData(userInfo.password, secretKey); + const password = userInfo.password + // const password = await encryptData(userInfo.password, secretKey) || '' const code = userInfo.code const uuid = userInfo.uuid return new Promise((resolve, reject) => {