【7.0.4】请求响应加密解密模块更新获取RSA实例方式

pull/22/head
18idc 2021-06-04 09:04:30 +08:00
parent 075fd4606d
commit ccaff60994
2 changed files with 33 additions and 1 deletions

View File

@ -18,6 +18,7 @@ import cn.stylefeng.roses.kernel.security.request.encrypt.constants.EncryptionCo
import cn.stylefeng.roses.kernel.security.request.encrypt.exception.EncryptionException; import cn.stylefeng.roses.kernel.security.request.encrypt.exception.EncryptionException;
import cn.stylefeng.roses.kernel.security.request.encrypt.exception.enums.EncryptionExceptionEnum; import cn.stylefeng.roses.kernel.security.request.encrypt.exception.enums.EncryptionExceptionEnum;
import cn.stylefeng.roses.kernel.security.request.encrypt.holder.EncryptionHolder; import cn.stylefeng.roses.kernel.security.request.encrypt.holder.EncryptionHolder;
import cn.stylefeng.roses.kernel.security.request.encrypt.holder.EncryptionRsaHolder;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -110,7 +111,7 @@ public class EncryptionRequestBodyAdvice implements RequestBodyAdvice {
} }
// 使用私钥解密出返回加密数据的key和请求的内容 // 使用私钥解密出返回加密数据的key和请求的内容
RSA rsa = new RSA(EncryptionConstants.PRIVATE_KEY, EncryptionConstants.PUBLIC_KEY); RSA rsa = EncryptionRsaHolder.getRsa();
// 先使用SM4解密出请求的json // 先使用SM4解密出请求的json
String objectString = jsonObject.getString("data"); String objectString = jsonObject.getString("data");

View File

@ -0,0 +1,31 @@
package cn.stylefeng.roses.kernel.security.request.encrypt.holder;
import cn.hutool.crypto.asymmetric.RSA;
import cn.stylefeng.roses.kernel.security.request.encrypt.constants.EncryptionConstants;
/**
* RSA
*
* @author luojie
* @date 2021/6/4 08:58
*/
public class EncryptionRsaHolder {
private static final ThreadLocal<RSA> RSA_HOLDER = new ThreadLocal<RSA>() {
@Override
protected RSA initialValue() {
return new RSA(EncryptionConstants.PRIVATE_KEY, EncryptionConstants.PUBLIC_KEY);
}
};
/**
* RSA
*
* @author luojie
* @date 2021/6/4 08:59
*/
public static RSA getRsa() {
return RSA_HOLDER.get();
}
}