Browse Source

feat: rsa

zhangjie 6 tháng trước cách đây
mục cha
commit
4f1ec4c48a
5 tập tin đã thay đổi với 21 bổ sung3 xóa
  1. 1 0
      package.json
  2. 6 0
      pnpm-lock.yaml
  3. 1 1
      src/store/modules/app/index.ts
  4. 11 0
      src/utils/rsa.ts
  5. 2 2
      src/views/login/login/index.vue

+ 1 - 0
package.json

@@ -50,6 +50,7 @@
     "gm": "^1.25.0",
     "image-size": "^1.1.1",
     "js-md5": "^0.8.3",
+    "jsencrypt": "^3.3.2",
     "lodash": "^4.17.21",
     "mitt": "^3.0.0",
     "nprogress": "^0.2.0",

+ 6 - 0
pnpm-lock.yaml

@@ -53,6 +53,7 @@ specifiers:
   husky: ^8.0.1
   image-size: ^1.1.1
   js-md5: ^0.8.3
+  jsencrypt: ^3.3.2
   less: ^4.1.3
   lint-staged: ^13.0.3
   lodash: ^4.17.21
@@ -97,6 +98,7 @@ dependencies:
   gm: 1.25.0
   image-size: 1.1.1
   js-md5: 0.8.3
+  jsencrypt: 3.3.2
   lodash: 4.17.21
   mitt: 3.0.1
   nprogress: 0.2.0
@@ -6254,6 +6256,10 @@ packages:
     dev: false
     optional: true
 
+  /jsencrypt/3.3.2:
+    resolution: {integrity: sha512-arQR1R1ESGdAxY7ZheWr12wCaF2yF47v5qpB76TtV64H1pyGudk9Hvw8Y9tb/FiTIaaTRUyaSnm5T/Y53Ghm/A==}
+    dev: false
+
   /jsesc/2.5.2:
     resolution: {integrity: sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA==}
     engines: {node: '>=4'}

+ 1 - 1
src/store/modules/app/index.ts

@@ -3,7 +3,7 @@ import { AppState } from './types';
 
 const useAppStore = defineStore('app', {
   state: (): AppState => ({
-    version: '1.0.1',
+    version: '1.0.4',
     domain: '',
     device: 'desktop',
     trackConfig: {

+ 11 - 0
src/utils/rsa.ts

@@ -0,0 +1,11 @@
+import JSEncrypt from 'jsencrypt';
+
+const PUBLIC_KEY = `MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDXl2bQu5E9JYpMaeWHCbGq3efy6S5y1PMwZp6iatu5KYhFJbZ+1oSPVCbz6ETNFx3sayk4m1lnoKmADaOr6Dyo8rWVlmw+yqjB5fzV7sJrla385OpsCDdznHBEK4v2ubQRSq86N2PFGXxSPekQNlmlwfae8ZLi6NGbrbnMRf8beQIDAQAB`;
+
+export function rsaEncrypt(content: string) {
+  const encrypt = new JSEncrypt();
+  encrypt.setPublicKey(PUBLIC_KEY);
+
+  const encrypted = encrypt.encrypt(content);
+  return encrypted || '';
+}

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

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