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