SignUtils.java 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package com.fdkankan.sign;
  2. import org.apache.commons.lang3.StringUtils;
  3. import org.json.JSONObject;
  4. import java.util.Date;
  5. public class SignUtils {
  6. public static Boolean checkSign(String sign,String appIdValue,String privateKey) {
  7. try {
  8. if(StringUtils.isBlank(sign)){
  9. return false;
  10. }
  11. String deTxt = RsaUtils.decipher(sign, privateKey);
  12. if(StringUtils.isBlank(deTxt)){
  13. return false;
  14. }
  15. JSONObject jsonObject = new JSONObject(deTxt);
  16. String appId = jsonObject.getString("appId");
  17. Long timestamp = jsonObject.getLong("timestamp");
  18. if(StringUtils.isBlank(appId) || timestamp == null){
  19. return false;
  20. }
  21. if(!appId.equals(appIdValue)){
  22. return false;
  23. }
  24. Long time = new Date().getTime();
  25. if((Math.abs( time -timestamp) >1000 * 60 *5){
  26. return false;
  27. }
  28. return true;
  29. }catch (Exception e){
  30. return false;
  31. }
  32. }
  33. }