Browse Source

feat: aes

sunxiao 1 month ago
parent
commit
9ef1ad6dbb
3 changed files with 48 additions and 0 deletions
  1. 6 0
      package-lock.json
  2. 1 0
      package.json
  3. 41 0
      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",
@@ -2662,6 +2663,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",

+ 41 - 0
src/views/login/LoginView.vue

@@ -6,6 +6,7 @@ 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 router = useRouter();
 const userStore = useUserStore();
@@ -44,7 +45,47 @@ const handleSubmit = async () => {
     loading.value = false;
   }
 }
+function AES_ECB_DECRYPT(textBase64, secretKey) {
+    var keyHex = CryptoJS.enc.Base64.parse(secretKey);
+    var decrypt = CryptoJS.AES.decrypt(textBase64, keyHex, {
+      "mode": CryptoJS.mode.ECB,
+      "padding": CryptoJS.pad.Pkcs7
+    });
+    return CryptoJS.enc.Utf8.stringify(decrypt);
+  }
+function AES_ECB_ENCRYPT(text, secretKey) {
+    var keyHex = CryptoJS.enc.Base64.parse(secretKey);
+    var messageHex = CryptoJS.enc.Utf8.parse(text);
+    var encrypted = CryptoJS.AES.encrypt(messageHex, keyHex, {
+      "mode": CryptoJS.mode.ECB,
+      // "padding": CryptoJS.pad.Pkcs5
+    });
+    return encrypted.toString();
+  }
+
+  // NgGqMDDZE1Qcwhd3iafotw==
+
+
+function decryptData(encryptedData) {
+  const bytes  = CryptoJS.AES.decrypt(encryptedData, 'qwertasdfg159753');
+  return JSON.parse(bytes.toString(CryptoJS.enc.Utf8));
+}
+
+  function encryptData(data) {
+  return CryptoJS.AES.encrypt(JSON.stringify(data), 'qwertasdfg159753').toString();
+}
+
+
+console.log( AES_ECB_DECRYPT('NgGqMDDZE1Qcwhd3iafotw==', 'qwertasdfg159753') );
+
+// const result = encryptData('admin123你好');
+// console.log( AES_ECB_ENCRYPT(  'admin123你好', 'qwertasdfg159753') );
+// console.log( "result", result );
+
+// console.log( decryptData('NgGqMDDZE1Qcwhd3iafotw==') );
 
+// clg
+// console.log( "decryptData", decryptData() );
 </script>
 
 <template>