瀏覽代碼

:sparkles: 加密解密隐藏接口

lag 7 月之前
父節點
當前提交
beaa058f77

+ 23 - 1
ghjg-item-datashare-server/src/main/java/com/shanghaichengdi/ghjgitem/controller/AuthController.java

@@ -10,10 +10,13 @@ import com.shanghaichengdi.ghjgitem.service.RedisService;
 import com.shanghaichengdi.ghjgitem.service.SysDatashareServiceNewService;
 import com.shanghaichengdi.ghjgitem.service.SysDatashareUserService;
 import com.shanghaichengdi.ghjgitem.util.ApiUtils;
+import com.shanghaichengdi.ghjgitem.util.Encodes;
 import com.shanghaichengdi.ghjgitem.util.JwtUtils;
 import com.shanghaichengdi.ghjgitem.vo.request.AuthRequest;
+import com.shanghaichengdi.ghjgitem.vo.request.DecryptReq;
 import com.shanghaichengdi.ghjgitem.vo.request.FrequencyCacheReq;
 import com.shanghaichengdi.ghjgitem.vo.response.ReturnMsg;
+import java.nio.charset.StandardCharsets;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
@@ -79,7 +82,7 @@ public class AuthController {
 
   @GetMapping("/checkToken/{tokenString}")
   public ReturnMsg checkToken(@PathVariable("tokenString") String tokenString) {
-    Objects.requireNonNull(tokenString,"tokenString不可为空");
+    Objects.requireNonNull(tokenString, "tokenString不可为空");
     Map<String, String> map = new HashMap<>();
     map.put("token", tokenString);
     String result = ApiUtils.api(map, OutsideInterface.AUTH_URL.getUrlString(), "checkToken");
@@ -97,4 +100,23 @@ public class AuthController {
     String o = redisService.getValue(Constants.TOKEN + Constants.SPLIT, token);
     return ReturnMsg.success(o);
   }
+
+  @PostMapping("/encrypt")
+  public ReturnMsg encrypt(@RequestBody Map<String,Object> req) {
+    JSONObject jsonObject = new JSONObject(req);
+    String mvData = Encodes.encodeBase64(
+        Encodes.aesEncrypt(jsonObject.toString().getBytes(StandardCharsets.UTF_8),
+            "ghThreeDataShare".getBytes(),
+            "ghThreeDataShare".getBytes()));
+    return ReturnMsg.success(mvData);
+  }
+
+  @PostMapping("/decrypt")
+  public ReturnMsg decrypt(@RequestBody DecryptReq req) {
+    String result = new String(Encodes.aesDecrypt(
+        Encodes.decodeBase64(req.getEncryptData()),
+        "ghThreeDataShare".getBytes(),
+        "ghThreeDataShare".getBytes()), StandardCharsets.UTF_8);
+    return ReturnMsg.success(result);
+  }
 }

+ 9 - 0
ghjg-item-datashare-server/src/main/java/com/shanghaichengdi/ghjgitem/vo/request/DecryptReq.java

@@ -0,0 +1,9 @@
+package com.shanghaichengdi.ghjgitem.vo.request;
+
+import lombok.Data;
+
+@Data
+public class DecryptReq {
+
+  String encryptData;
+}