Przeglądaj źródła

参数加密解密处理

wangfeng 5 lat temu
rodzic
commit
6782b551c1

+ 60 - 0
prec-service/src/main/java/com/diagbot/facade/PrecEncryptFacade.java

@@ -0,0 +1,60 @@
+package com.diagbot.facade;
+
+import com.diagbot.util.AESCipher;
+import com.diagbot.vo.PrecMapVO;
+import org.springframework.stereotype.Component;
+
+import java.text.ParseException;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author wangfeng
+ * @Description:
+ * @date 2020-05-11 15:08
+ */
+@Component
+public class PrecEncryptFacade {
+    private static final String IV_STRING = "z76rxggpnykxeyb1";
+
+
+    public PrecMapVO getEncryption(PrecMapVO precMapVO) throws ParseException {
+        //patientInfo  patientName
+        Map<String,String> map = precMapVO.getMap();
+        Map<String,String> mapNew =new HashMap<String, String>();
+        try {
+            for(String key : map.keySet()){
+                String value = map.get(key);
+                String aesEncrypValue = AESCipher.aesEncryptString(value,IV_STRING);
+                mapNew.put(key,aesEncrypValue);
+                System.out.println(key+"  "+aesEncrypValue);
+            }
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        PrecMapVO data = new PrecMapVO();
+        data.setMap(mapNew);
+        return data;
+    }
+
+    public PrecMapVO getDecode(PrecMapVO precVO) {
+        //patientInfo  patientName
+        Map<String,String> map = precVO.getMap();
+        Map<String,String> mapNew =new HashMap<String, String>();
+        try {
+            for(String key : map.keySet()){
+                String value = map.get(key);
+                String aesEncrypValue = AESCipher.aesDecryptString(value,IV_STRING);
+                mapNew.put(key,aesEncrypValue);
+                System.out.println(key+"  "+aesEncrypValue);
+            }
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        PrecMapVO data = new PrecMapVO();
+        data.setMap(mapNew);
+        return data;
+    }
+}

+ 20 - 0
prec-service/src/main/java/com/diagbot/vo/PrecMapVO.java

@@ -0,0 +1,20 @@
+package com.diagbot.vo;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.Date;
+import java.util.Map;
+
+/**
+ * @author wangfeng
+ * @Description:
+ * @date 2020-05-11 14:47
+ */
+@Setter
+@Getter
+public class PrecMapVO {
+    //请求数据
+    private  Map<String,String> map;
+}

+ 47 - 0
prec-service/src/main/java/com/diagbot/web/PrecEncryptController.java

@@ -0,0 +1,47 @@
+package com.diagbot.web;
+
+import com.diagbot.annotation.SysLogger;
+import com.diagbot.dto.RespDTO;
+import com.diagbot.facade.PrecEncryptFacade;
+import com.diagbot.vo.PrecMapVO;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.validation.Valid;
+import java.text.ParseException;
+
+/**
+ * @author wangfeng
+ * @Description:
+ * @date 2020-05-11 14:44
+ */
+@RestController
+@RequestMapping("/prec")
+@Api(value = "预问诊请求API[by:wangfeng]", tags = { "预问诊请求API" })
+@SuppressWarnings("unchecked")
+public class PrecEncryptController {
+
+    @Autowired
+    private PrecEncryptFacade precEncryptFacade;
+
+    @ApiOperation(value = "请求参数加密:[by:wangfeng]",
+            notes = "Map<String ,String> map")
+    @PostMapping("/getEncryption")
+    @SysLogger("getEncryption")
+    public RespDTO<PrecMapVO> getEncryption(@RequestBody PrecMapVO precMapVO) throws ParseException {
+        return RespDTO.onSuc(precEncryptFacade.getEncryption(precMapVO));
+    }
+
+    @ApiOperation(value = "请求参数解密 :[by:wangfeng]",
+            notes = "Map<String ,String> map")
+    @PostMapping("/getDecode")
+    @SysLogger("getDecode")
+    public RespDTO<PrecMapVO> getDecode(@RequestBody @Valid PrecMapVO precVO) throws ParseException{
+        return RespDTO.onSuc(precEncryptFacade.getDecode(precVO));
+    }
+}