Commit 45082688 authored by zhouxudong's avatar zhouxudong

反扒加密

parent 7a4b71c8
......@@ -3,10 +3,11 @@ package com.lyy.admin.common.encrypt;
import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.RSA;
import cn.hutool.crypto.symmetric.AES;
import cn.hutool.json.JSONUtil;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.lyy.admin.common.anno.EncryptBusiness;
import com.lyy.admin.common.constant.Constants;
import com.lyy.admin.common.utils.AjaxResult;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Value;
......@@ -41,6 +42,7 @@ public class EncrptBusinessResponse implements ResponseBodyAdvice<Object> {
}
/** 数据响应进行加密 */
@SneakyThrows
@Override
public Object beforeBodyWrite(
Object result,
......@@ -60,14 +62,15 @@ public class EncrptBusinessResponse implements ResponseBodyAdvice<Object> {
String sign = servletRequest.getServletRequest().getHeader(Constants.secure);
//获取对称加密的key
String decrypt = rsa.decryptStr(sign, KeyType.PrivateKey);
ObjectMapper objectMapper=new ObjectMapper();
// 获取key的字节
AES aes = new AES("CBC","PKCS7Padding", decrypt.getBytes(),decrypt.getBytes(StandardCharsets.UTF_8));
boolean isStringResult = methodParameter.getParameterType().equals(String.class);
if (isStringResult) {
return JSONUtil.toJsonStr(AjaxResult.success("操作成功",aes.encryptBase64(result.toString())));
return objectMapper.writeValueAsString(AjaxResult.success("操作成功",aes.encryptBase64(result.toString())));
}
// 如果msg和data存在的话,则进行加密,最后进行返回
return AjaxResult.success("操作成功",aes.encryptBase64(JSONUtil.toJsonStr(result)));
return AjaxResult.success("操作成功",aes.encryptBase64(objectMapper.writeValueAsString(result)));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment