Commit 212d9fbd authored by 以墨为白's avatar 以墨为白 🎧

加密优化

parent a55e27c4
......@@ -116,8 +116,7 @@ public class SignatureVerificationFilter extends OncePerRequestFilter {
// 校验appId
AppStore appStore = this.appStoreService.getAppSecretInfo(appId);
String appSecret = appStore.getAppSecret();
if (!StringUtils.hasText(appSecret)) {
if (appStore == null || appStore.getAppSecret() == null) {
this.write(response, "appId无效:" + appId);
return false;
}
......@@ -134,10 +133,12 @@ public class SignatureVerificationFilter extends OncePerRequestFilter {
body = objectMapper.writeValueAsString(objectMap);
logger.info("请求参数appId: {}, nonce: {}, timestampStr: {}, 原始body: {}, deptCode: {}", appId, nonce, timestampStr, body, deptCode);
String appSecret = appStore.getAppSecret();
body = EncryptUtil.getInstance().AESEncode(body, appSecret);
// logger.info("appSecret{}加密后body: {}", appSecret,body);
logger.info("appSecret:{}加密后body: {}", appSecret,body);
// 校验签名appId+nonce+timestampStr+aes(body,secret)+detCode
String data = String.format("%s%s%s%s%s", appId, nonce, timestampStr, body, deptCode);
logger.info("待签名数据:{}", data);
String generatedSignature = DigestUtil.md5Hex(data);
if (!generatedSignature.equals(sign)) {
logger.warn("签名有误,generatedSignature:{},sign:{},appId:{},nonce:{},timestampStr:{},deptCode:{}", generatedSignature, sign, appId, nonce, timestampStr, deptCode);
......
......@@ -15,13 +15,16 @@ public class TestAppStore {
@Test
@DisplayName("新增AppId")
public void addAppId() {
AppStoreDTO appStoreDTO = new AppStoreDTO();
appStoreDTO.setAppKey("scale");
appStoreDTO.setAppSecret(DigestUtil.md5Hex("scale"));
appStoreDTO.setDeptCode("3302020201");
for (int i = 0; i < 10000; i++) {
AppStoreDTO appStoreDTO = new AppStoreDTO();
appStoreDTO.setAppKey("scale");
appStoreDTO.setAppSecret(DigestUtil.md5Hex("scale"));
appStoreDTO.setDeptCode("330102");
TestHttpUtil.signatureAndRequest("/rest/appStore/updateAppIdSecret", appStoreDTO, AppStoreDTO.class);
TestHttpUtil.signatureAndRequest("/rest/appStore/insertAppStore", appStoreDTO, AppStoreDTO.class);
TestHttpUtil.signatureAndRequest("/rest/appStore/insertAppStore", appStoreDTO, AppStoreDTO.class);
}
// TestHttpUtil.signatureAndRequest("/rest/appStore/insertAppStore", appStoreDTO, AppStoreDTO.class);
// TestHttpUtil.signatureAndRequest("/rest/appStore/insertAppStore", appStoreDTO);
}
......
......@@ -14,9 +14,9 @@ public class TestHttpUtil {
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(TestHttpUtil.class);
static String nonce = "2";
static String timestampStr = "21";
static String appId = "scale";
static String appSecret = DigestUtil.md5Hex("scale");;
static String deptCode = "3302020201";
static String appId = "1872576325743943682";
static String appSecret = DigestUtil.md5Hex("2");;
static String deptCode = "330102";
private static final ObjectMapper objectMapper = new ObjectMapper();
......
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