|
@@ -53,22 +53,22 @@ public class CheckSignatureAspect {
|
|
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
|
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
|
String signature = request.getHeader("signature");
|
|
String signature = request.getHeader("signature");
|
|
if(StrUtil.isEmpty(signature)){
|
|
if(StrUtil.isEmpty(signature)){
|
|
- throw new BusinessException(ErrorCode.FAILURE_CODE_3003.code(), "请求头必须携带签名");
|
|
|
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_3003.code(), "signature cannot be empty");
|
|
}
|
|
}
|
|
String appCode = request.getParameter("appCode");
|
|
String appCode = request.getParameter("appCode");
|
|
if(StrUtil.isEmpty(appCode)){
|
|
if(StrUtil.isEmpty(appCode)){
|
|
- throw new BusinessException(ErrorCode.FAILURE_CODE_3003.code(), "appCode不能为空");
|
|
|
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_3003.code(), "appCode cannot be empty");
|
|
}
|
|
}
|
|
String timestamp = request.getParameter("timestamp");
|
|
String timestamp = request.getParameter("timestamp");
|
|
if(StrUtil.isEmpty(timestamp)){
|
|
if(StrUtil.isEmpty(timestamp)){
|
|
- throw new BusinessException(ErrorCode.FAILURE_CODE_3003.code(), "timestamp不能为空");
|
|
|
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_3003.code(), "timestamp cannot be empty");
|
|
}
|
|
}
|
|
//时间戳有效时间是10秒
|
|
//时间戳有效时间是10秒
|
|
Instant now = Instant.now();
|
|
Instant now = Instant.now();
|
|
long epochSecond = now.getEpochSecond();
|
|
long epochSecond = now.getEpochSecond();
|
|
long expiraSecond = Long.valueOf(timestamp) + 10 * 60L;
|
|
long expiraSecond = Long.valueOf(timestamp) + 10 * 60L;
|
|
if(expiraSecond < epochSecond){
|
|
if(expiraSecond < epochSecond){
|
|
- throw new BusinessException(ErrorCode.FAILURE_CODE_3003.code(), "签名已失效");
|
|
|
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_3003.code(), "signature expired");
|
|
}
|
|
}
|
|
|
|
|
|
AppConfig appConfig = appConfigService.getByAppCode(appCode);
|
|
AppConfig appConfig = appConfigService.getByAppCode(appCode);
|
|
@@ -86,14 +86,21 @@ public class CheckSignatureAspect {
|
|
log.info("解密:{}", signature);
|
|
log.info("解密:{}", signature);
|
|
String[] split = signature.split("-");
|
|
String[] split = signature.split("-");
|
|
if(split.length != 2){
|
|
if(split.length != 2){
|
|
- throw new BusinessException(ErrorCode.FAILURE_CODE_3003.code(), "签名不匹配");
|
|
|
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_3003.code(), "signature mismatch");
|
|
}
|
|
}
|
|
String signatureAppCode = split[0];
|
|
String signatureAppCode = split[0];
|
|
String signatureTimestamp = split[1];
|
|
String signatureTimestamp = split[1];
|
|
if(!appCode.equals(signatureAppCode) || !timestamp.equals(signatureTimestamp)){
|
|
if(!appCode.equals(signatureAppCode) || !timestamp.equals(signatureTimestamp)){
|
|
- throw new BusinessException(ErrorCode.FAILURE_CODE_3003.code(), "签名不匹配");
|
|
|
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_3003.code(), "signature mismatch");
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public static void main(String[] args) {
|
|
|
|
+ String publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCHmJkGNg0N0tKroJAbqdO6ndgdEgJBnClW3KhzUCQSLVYhBvewjlXRmc1KQbI7QHpcdbuhvGT/RVVu4npVRPnQilGSyOxLbDI4TKaM6ZMSYQ1RS5vTj2HbvJ2s21AjEhhRcDYvSEDs4KsZaOmta/Cfok8jfG46o3UB6LkwzCMHtQIDAQAB";
|
|
|
|
+ String test = "af9c663f3fd744c6bf40dbcd1c9aada3-" + "1719828816";
|
|
|
|
+ String s = RsaUtil.create(null, publicKey).encryptByPublicKey(test);
|
|
|
|
+ System.out.println(s);
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|