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

加密优化

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