Browse Source

Merge branch '2024-10-24/fetaure-AES'

sunxiao 2 weeks ago
parent
commit
3c15b84cf6
2 changed files with 13 additions and 1 deletions
  1. 1 0
      package.json
  2. 12 1
      src/store/modules/user.js

+ 1 - 0
package.json

@@ -24,6 +24,7 @@
     "@vueup/vue-quill": "1.2.0",
     "@vueuse/core": "10.6.1",
     "axios": "0.27.2",
+    "crypto-js": "^4.2.0",
     "echarts": "^5.5.0",
     "element-plus": "2.4.3",
     "file-saver": "2.0.5",

+ 12 - 1
src/store/modules/user.js

@@ -1,6 +1,17 @@
 import { login, logout, getInfo } from '@/api/login'
 import { getToken, setToken, removeToken } from '@/utils/auth'
 import defAva from '@/assets/images/profile.jpg'
+import CryptoJS from 'crypto-js';
+
+const SECRET_KEY = 'qwertasdfg159753'
+function AES_ECB_ENCRYPT(text) {
+  var keyHex = CryptoJS.enc.Utf8.parse(SECRET_KEY);
+  var messageHex = CryptoJS.enc.Utf8.parse(text);
+  var encrypted = CryptoJS.AES.encrypt(messageHex, keyHex, {
+    "mode": CryptoJS.mode.ECB
+  });
+  return encrypted.toString();
+}
 
 const useUserStore = defineStore(
   'user',
@@ -17,7 +28,7 @@ const useUserStore = defineStore(
       // 登录
       login(userInfo) {
         const username = userInfo.username.trim()
-        const password = userInfo.password
+        const password = AES_ECB_ENCRYPT(userInfo.password)
         const code = userInfo.code
         const uuid = userInfo.uuid
         return new Promise((resolve, reject) => {