提交修改
This commit is contained in:
parent
b13057523b
commit
9b9c96cb79
105
api-mapper/src/main/java/com/heyu/api/data/utils/AesUtil.java
Normal file
105
api-mapper/src/main/java/com/heyu/api/data/utils/AesUtil.java
Normal file
@ -0,0 +1,105 @@
|
||||
//
|
||||
// Source code recreated from a .class file by IntelliJ IDEA
|
||||
// (powered by FernFlower decompiler)
|
||||
//
|
||||
|
||||
package com.heyu.api.data.utils;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
|
||||
import javax.crypto.*;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
|
||||
public class AesUtil {
|
||||
|
||||
|
||||
private static byte[] doEncrypt(String content, String password) {
|
||||
try {
|
||||
KeyGenerator kgen = KeyGenerator.getInstance("AES");
|
||||
SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
|
||||
secureRandom.setSeed(password.getBytes());
|
||||
kgen.init(128, secureRandom);
|
||||
SecretKey secretKey = kgen.generateKey();
|
||||
byte[] enCodeFormat = secretKey.getEncoded();
|
||||
SecretKeySpec key = new SecretKeySpec(enCodeFormat, "AES");
|
||||
Cipher cipher = Cipher.getInstance("AES");
|
||||
byte[] byteContent = content.getBytes("UTF-8");
|
||||
cipher.init(1, key);
|
||||
byte[] result = cipher.doFinal(byteContent);
|
||||
return result;
|
||||
} catch (NoSuchAlgorithmException var10) {
|
||||
System.out.println("encrypt NoSuchAlgorithmException");
|
||||
} catch (NoSuchPaddingException var11) {
|
||||
System.out.println("encrypt NoSuchPaddingException");
|
||||
} catch (InvalidKeyException var12) {
|
||||
System.out.println("encrypt InvalidKeyException");
|
||||
} catch (UnsupportedEncodingException var13) {
|
||||
System.out.println("encrypt UnsupportedEncodingException");
|
||||
} catch (IllegalBlockSizeException var14) {
|
||||
System.out.println("encrypt IllegalBlockSizeException");
|
||||
} catch (BadPaddingException var15) {
|
||||
System.out.println("encrypt BadPaddingException");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String decrypt(String contentStr, String password) {
|
||||
try {
|
||||
byte[] content = Base64.decodeBase64(contentStr.getBytes());
|
||||
KeyGenerator kgen = KeyGenerator.getInstance("AES");
|
||||
SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
|
||||
secureRandom.setSeed(password.getBytes());
|
||||
kgen.init(128, secureRandom);
|
||||
SecretKey secretKey = kgen.generateKey();
|
||||
byte[] enCodeFormat = secretKey.getEncoded();
|
||||
SecretKeySpec key = new SecretKeySpec(enCodeFormat, "AES");
|
||||
Cipher cipher = Cipher.getInstance("AES");
|
||||
cipher.init(2, key);
|
||||
byte[] result = cipher.doFinal(content);
|
||||
return new String(result);
|
||||
} catch (NoSuchAlgorithmException var10) {
|
||||
System.out.println("decrypt NoSuchAlgorithmException");
|
||||
} catch (NoSuchPaddingException var11) {
|
||||
System.out.println("decrypt NoSuchPaddingException");
|
||||
} catch (InvalidKeyException var12) {
|
||||
System.out.println("decrypt InvalidKeyException");
|
||||
} catch (IllegalBlockSizeException var13) {
|
||||
System.out.println("decrypt IllegalBlockSizeException");
|
||||
} catch (BadPaddingException var14) {
|
||||
System.out.println("decrypt BadPaddingException");
|
||||
}
|
||||
|
||||
return contentStr;
|
||||
}
|
||||
|
||||
private static String encrypt(String value, String encrypt_password) {
|
||||
return new String(Base64.encodeBase64(doEncrypt(value, encrypt_password)));
|
||||
}
|
||||
|
||||
public static String decrypt(String value) {
|
||||
return decrypt(value, getPassword());
|
||||
}
|
||||
|
||||
|
||||
private static String getPassword() {
|
||||
String password = "123456";
|
||||
return password;
|
||||
}
|
||||
|
||||
public static String encrypt(String value) {
|
||||
return new String(Base64.encodeBase64(doEncrypt(value, getPassword())));
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String encode = encrypt("xxxxxx493983333333333339438943", getPassword());
|
||||
|
||||
|
||||
System.out.println(encode);
|
||||
System.out.println(decrypt(encode, getPassword()));
|
||||
}
|
||||
}
|
||||
@ -4,10 +4,9 @@ import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.heyu.api.common.LogAspect;
|
||||
import com.heyu.api.data.dto.BuyerDTO;
|
||||
import com.heyu.api.data.entity.vv.VvReverseOrderEntity;
|
||||
import com.heyu.api.data.service.bussiness.RedisSettingService;
|
||||
import com.heyu.api.data.utils.OrderUtil;
|
||||
import com.heyu.api.data.utils.RedisUtils;
|
||||
import com.heyu.api.data.utils.StringUtils;
|
||||
import com.heyu.api.data.utils.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.Signature;
|
||||
@ -26,7 +25,9 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 日志aop
|
||||
@ -105,6 +106,7 @@ public class ZhenZhenLogAop {
|
||||
for (Object argArr : argArrs) {
|
||||
argArr.getClass().getDeclaredMethods();
|
||||
List<Method> methods = new ArrayList<>();
|
||||
|
||||
getClassDeclaredMethods(argArr.getClass(),methods);
|
||||
|
||||
for (Method m : methods) {
|
||||
@ -129,6 +131,13 @@ public class ZhenZhenLogAop {
|
||||
}
|
||||
}
|
||||
result = point.proceed();
|
||||
|
||||
if(result instanceof R){
|
||||
R r = (R) result;
|
||||
Object object = r.getData();
|
||||
convertImage(object);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("LogAop set error " + sb.toString(), e);
|
||||
} finally {
|
||||
@ -140,20 +149,83 @@ public class ZhenZhenLogAop {
|
||||
}
|
||||
|
||||
|
||||
public static void convertImage(Object object){
|
||||
if(object == null){
|
||||
return ;
|
||||
}
|
||||
if(object instanceof List){
|
||||
List list = (List) object;
|
||||
for (Object o : list) {
|
||||
convertImage(o);
|
||||
}
|
||||
}else if (object instanceof Map) {
|
||||
Map map = (Map) object;
|
||||
for (Object key : map.keySet()) {
|
||||
Object value = map.get(key);
|
||||
convertImage(value);
|
||||
}
|
||||
}else if (object.getClass().isArray()) {
|
||||
Object[] array = (Object[]) object;
|
||||
for (Object o : array) {
|
||||
convertImage(o);
|
||||
}
|
||||
} else if (SanUtils.isBasicDataTypes(object.getClass())) {
|
||||
return;
|
||||
} else {
|
||||
List<Method> methods = new ArrayList<>();
|
||||
getClassDeclaredMethods(object.getClass(), methods);
|
||||
Map<String, Method> methodMap = new HashMap<>();
|
||||
for (Method method : methods) {
|
||||
methodMap.put(method.getName(), method);
|
||||
}
|
||||
|
||||
for (Method method : methods) {
|
||||
try {
|
||||
method.setAccessible(true);
|
||||
if (method.getName().startsWith("get")) {
|
||||
Object image = method.invoke(object);
|
||||
// 如果是基本数据类型
|
||||
if (SanUtils.isBasicDataTypes(method.getReturnType())) {
|
||||
if (method.getReturnType() == String.class) {
|
||||
String str = (String)image;
|
||||
if (str!=null
|
||||
&& str.startsWith("http://heyuimage.ihzhy.com")) {
|
||||
String setMethodName = "set" + method.getName().substring(3);
|
||||
Method setMethod = methodMap.get(setMethodName);
|
||||
String newImage = image + "?key=xxxxxxx";
|
||||
setMethod.invoke(object, new Object[]{newImage});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
convertImage(image);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("LogAop convertImage error " + method.getName() + ",Object:{}" + JSON.toJSONString(object), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
VvReverseOrderEntity vvReverseOrderEntity = new VvReverseOrderEntity();
|
||||
vvReverseOrderEntity.setStatus("http://heyuimage.ihzhy.com/48a458c49f5e0b9c74eeb163b577a49d.mp4");
|
||||
|
||||
convertImage(vvReverseOrderEntity);
|
||||
System.out.println(JSON.toJSONString(vvReverseOrderEntity));
|
||||
}
|
||||
|
||||
public static void getClassDeclaredMethods( Class entityType, List<Method> methods){
|
||||
|
||||
if(entityType == Object.class){
|
||||
return ;
|
||||
}
|
||||
|
||||
Method method [] = entityType.getDeclaredMethods();
|
||||
|
||||
for (Method method1 : method) {
|
||||
methods.add(method1);
|
||||
}
|
||||
|
||||
getClassDeclaredMethods(entityType.getSuperclass(), methods);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user