浏览代码

中煤报文参数修改

wks 3 年之前
父节点
当前提交
28540c4bb2
共有 1 个文件被更改,包括 12 次插入9 次删除
  1. 12 9
      src/main/java/com/ydtech/modules/order/utils/AESUtilsWithDataBase.java

+ 12 - 9
src/main/java/com/ydtech/modules/order/utils/AESUtilsWithDataBase.java

@@ -2,6 +2,7 @@ package com.ydtech.modules.order.utils;
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.serializer.SerializerFeature;
+import com.ydtech.modules.order.entity.api.zm.response.ModelsQueryResponse;
 import lombok.extern.slf4j.Slf4j;
 
 import javax.crypto.Cipher;
@@ -22,12 +23,13 @@ public class AESUtilsWithDataBase {
 //    private static final String sessionKey = "1237891234567589";
 
     /**
+
      * AES 加密操作  ECBPK5Hex
      *
      * @param content 待加密内容
      * @return 返回Base64转码后的加密数据
      */
-    public static String encryptECBPK5Hex(String content, String sessionKey) {
+    public static String encryptECBPK5Hex(String content, String sessionKey)  {
         byte[] result = null;
         if (content == null || "".equals(content)) {
             return content;
@@ -43,7 +45,7 @@ public class AESUtilsWithDataBase {
              * 3. 补码方式(包含nopadding/PKCS5Padding等等)
              * 依据这三个参数可以创建很多种加密方式
              */
-            synchronized (Cipher.class) {
+            synchronized(Cipher.class) {
                 Cipher cipher = Cipher.getInstance(ECB_PKCS5_PADDING);//"AES/ECB/PKCS5Padding";
                 cipher.init(Cipher.ENCRYPT_MODE, skeySpec);// 初始化为加密模式的密码器
                 result = cipher.doFinal(byteContent);// 加密
@@ -62,7 +64,7 @@ public class AESUtilsWithDataBase {
      */
     public static String decryptECBPK5Hex(String content, String sessionKey) {
         String returnStr = content;
-        byte[] result = null;
+        byte[] result;
         if (content == null || "".equals(content)) {
             return content;
         }
@@ -76,12 +78,12 @@ public class AESUtilsWithDataBase {
                 result = cipher.doFinal(hexToByte(content));
             }
             returnStr = new String(result, CODE_TYPE);
-        } catch (Exception ex) {
+        }catch (Exception ex) {
         }
         return returnStr;
     }
 
-    public static String byteToHex(byte[] bytes) {
+    public static String byteToHex(byte[] bytes){
         String strHex = "";
         StringBuilder sb = new StringBuilder("");
         for (int n = 0; n < bytes.length; n++) {
@@ -100,17 +102,18 @@ public class AESUtilsWithDataBase {
             m = i * 2 + 1;
             n = m + 1;
             int intVal = Integer.decode("0x" + hex.substring(i * 2, m) + hex.substring(m, n));
-            ret[i] = (byte) intVal;
+            ret[i] = Byte.valueOf((byte)intVal);
         }
         return ret;
     }
 
+
     public static <T> T decryptMessage(String s, Class<T> c, String message, String sessionKey) {
         log.info("---------> 解密前的参数:{}", s);
         // 解密
-        String s1 = AESUtilsWithDataBase.decryptECBPK5Hex(s,  sessionKey);
-        log.info("---------> {}:{}", message, s1);
-        return JSON.parseObject(s1, c);
+        String text = decryptECBPK5Hex(s.replace("\n", ""),  sessionKey);
+        log.info("---------> {}:{}", message, text);
+        return JSON.parseObject(text, c);
     }
 
 }