Преглед изворни кода

feat: 登录密码加密调整

zhangjie пре 6 месеци
родитељ
комит
4600743325
2 измењених фајлова са 28 додато и 7 уклоњено
  1. 26 5
      src/utils/crypto.ts
  2. 2 2
      src/views/login/login/index.vue

+ 26 - 5
src/utils/crypto.ts

@@ -2,6 +2,8 @@ import Base64 from 'crypto-js/enc-base64';
 import Utf8 from 'crypto-js/enc-utf8';
 import Utf8 from 'crypto-js/enc-utf8';
 import AES from 'crypto-js/aes';
 import AES from 'crypto-js/aes';
 import SHA1 from 'crypto-js/sha1';
 import SHA1 from 'crypto-js/sha1';
+import ECB from 'crypto-js/mode-ecb';
+import Pkcs7 from 'crypto-js/pad-pkcs7';
 
 
 export const getBase64 = (content: string): string => {
 export const getBase64 = (content: string): string => {
   const words = Utf8.parse(content);
   const words = Utf8.parse(content);
@@ -10,16 +12,35 @@ export const getBase64 = (content: string): string => {
   return base64Str;
   return base64Str;
 };
 };
 
 
-export const getAES = (content: string): string => {
-  const KEY = '1234567890123456';
-  const IV = '1234567890123456';
+export const AESEncode = (content: string): string => {
+  const KEY = 'Qmth87863577qmth';
+  // const IV = '1234567890123456';
 
 
   const key = Utf8.parse(KEY);
   const key = Utf8.parse(KEY);
-  const iv = Utf8.parse(IV);
-  const encrypted = AES.encrypt(content, key, { iv });
+  // const iv = Utf8.parse(IV);
+  const encrypted = AES.encrypt(content, key, {
+    // iv,
+    mode: ECB,
+    padding: Pkcs7,
+  });
   return encrypted.toString();
   return encrypted.toString();
 };
 };
 
 
+export const AESDecode = (content: string): string => {
+  const KEY = 'Qmth87863577qmth';
+  // const IV = "1234567890123456";
+
+  const key = Utf8.parse(KEY);
+
+  // const iv = Utf8.parse(IV);
+  const decrypted = AES.decrypt(content, key, {
+    // iv: iv,
+    mode: ECB,
+    padding: Pkcs7,
+  });
+  return decrypted.toString(Utf8);
+};
+
 type AuthType = 'token' | 'secret';
 type AuthType = 'token' | 'secret';
 interface AuthInfo {
 interface AuthInfo {
   uri: string;
   uri: string;

+ 2 - 2
src/views/login/login/index.vue

@@ -64,7 +64,7 @@
   import type { FormInstance } from '@arco-design/web-vue/es/form';
   import type { FormInstance } from '@arco-design/web-vue/es/form';
   import useLoading from '@/hooks/loading';
   import useLoading from '@/hooks/loading';
   import { login, schoolList, sysMenu } from '@/api/user';
   import { login, schoolList, sysMenu } from '@/api/user';
-  import { getBase64 } from '@/utils/crypto';
+  import { AESEncode } from '@/utils/crypto';
   import { useAppStore, useUserStore } from '@/store';
   import { useAppStore, useUserStore } from '@/store';
   import { UserSchoolInfoType } from '@/store/modules/user/types';
   import { UserSchoolInfoType } from '@/store/modules/user/types';
   import type { LoginData } from '@/api/types/user';
   import type { LoginData } from '@/api/types/user';
@@ -134,7 +134,7 @@
 
 
     setLoading(true);
     setLoading(true);
     const datas = objAssign(formData, {});
     const datas = objAssign(formData, {});
-    datas.password = getBase64(formData.password);
+    datas.password = AESEncode(formData.password);
     const data = await login(datas).catch(() => {});
     const data = await login(datas).catch(() => {});
     setLoading(false);
     setLoading(false);
     if (!data) return;
     if (!data) return;