Browse Source

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

sunxiao 2 weeks ago
parent
commit
858f6a93cf
3 changed files with 31 additions and 1 deletions
  1. 6 0
      package-lock.json
  2. 1 0
      package.json
  3. 24 1
      src/views/login/LoginView.vue

+ 6 - 0
package-lock.json

@@ -11,6 +11,7 @@
         "@vueuse/core": "^10.9.0",
         "autofit.js": "^3.1.3",
         "axios": "^1.6.8",
+        "crypto-js": "^4.2.0",
         "echarts": "^5.5.0",
         "echarts-gl": "^2.0.9",
         "element-plus": "^2.8.1",
@@ -2686,6 +2687,11 @@
         "node": ">= 8"
       }
     },
+    "node_modules/crypto-js": {
+      "version": "4.2.0",
+      "resolved": "https://registry.npmmirror.com/crypto-js/-/crypto-js-4.2.0.tgz",
+      "integrity": "sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q=="
+    },
     "node_modules/css-render": {
       "version": "0.15.14",
       "resolved": "https://registry.npmmirror.com/css-render/-/css-render-0.15.14.tgz",

+ 1 - 0
package.json

@@ -18,6 +18,7 @@
     "@vueuse/core": "^10.9.0",
     "autofit.js": "^3.1.3",
     "axios": "^1.6.8",
+    "crypto-js": "^4.2.0",
     "echarts": "^5.5.0",
     "echarts-gl": "^2.0.9",
     "element-plus": "^2.8.1",

+ 24 - 1
src/views/login/LoginView.vue

@@ -6,6 +6,9 @@ import { SvgIcon } from '@/components';
 import { useUserStore } from '@/stores/modules/userStore';
 import { userApi } from '@/api/user';
 import { TheArchival } from "@/components"
+import CryptoJS from 'crypto-js';
+
+const SECRET_KEY = 'qwertasdfg159753'
 
 const router = useRouter();
 const userStore = useUserStore();
@@ -30,7 +33,7 @@ const handleSubmit = async () => {
 
   try {
     loading.value = true;
-    const { token } = await userApi.postLogin({ username, password, type: 0 });
+    const { token } = await userApi.postLogin({ username, password: AES_ECB_ENCRYPT(password), type: 0 });
     userStore.setUserInfo({ token });
     const { user } = await userApi.getUserInfo();
     errorMsg.value = '';
@@ -45,6 +48,26 @@ const handleSubmit = async () => {
   }
 }
 
+// 加密
+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();
+}
+
+// 解密
+function AES_ECB_DECRYPT(textBase64) {
+  var keyHex = CryptoJS.enc.Utf8.parse(SECRET_KEY);
+  var decrypt = CryptoJS.AES.decrypt(textBase64, keyHex, {
+    "mode": CryptoJS.mode.ECB,
+    "padding": CryptoJS.pad.Pkcs7
+  });
+  return CryptoJS.enc.Utf8.stringify(decrypt);
+}
+
 </script>
 
 <template>