mirror of https://gitee.com/stylefeng/roses
【7.0.4】请求响应加密解密模块更新获取RSA实例方式
parent
075fd4606d
commit
ccaff60994
|
@ -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");
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue