瀏覽代碼

修改rsa加密方式

初志鑫 4 年之前
父節點
當前提交
f3780f8ccf
共有 2 個文件被更改,包括 4 次插入3 次删除
  1. 2 0
      mock/controller/user.js
  2. 2 3
      src/utils/encrypt.js

+ 2 - 0
mock/controller/user.js

@@ -15,6 +15,8 @@ export default [
         msg: "success",
         data: {
           mockServer: true,
+          publicKey:
+            "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDBT2vr+dhZElF73FJ6xiP181txKWUSNLPQQlid6DUJhGAOZblluafIdLmnUyKE8mMHhT3R+Ib3ssZcJku6Hn72yHYj/qPkCGFv0eFo7G+GJfDIUeDyalBN0QsuiE/XzPHJBuJDfRArOiWvH0BXOv5kpeXSXM8yTt5Na1jAYSiQ/wIDAQAB",
         },
       };
     },

+ 2 - 3
src/utils/encrypt.js

@@ -13,14 +13,13 @@ const privateKey =
 export async function encryptedData(data) {
   let publicKey = "";
   const res = await getPublicKey();
-  publicKey = res.data;
-  if (publicKey.mockServer) {
+  publicKey = res.data.publicKey;
+  if (res.data.mockServer) {
     publicKey = "";
   }
   if (publicKey == "") {
     return data;
   }
-
   const encrypt = new JSEncrypt();
   encrypt.setPublicKey(
     `-----BEGIN PUBLIC KEY-----${publicKey}-----END PUBLIC KEY-----`