123456789101112131415161718192021222324252627282930313233343536373839 |
- package com.fdkankan.sign;
- import org.apache.commons.lang3.StringUtils;
- import org.json.JSONObject;
- import java.util.Date;
- public class SignUtils {
- public static Boolean checkSign(String sign,String appIdValue,String privateKey) {
- try {
- if(StringUtils.isBlank(sign)){
- return false;
- }
- String deTxt = RsaUtils.decipher(sign, privateKey);
- if(StringUtils.isBlank(deTxt)){
- return false;
- }
- JSONObject jsonObject = new JSONObject(deTxt);
- String appId = jsonObject.getString("appId");
- Long timestamp = jsonObject.getLong("timestamp");
- if(StringUtils.isBlank(appId) || timestamp == null){
- return false;
- }
- if(!appId.equals(appIdValue)){
- return false;
- }
- Long time = new Date().getTime();
- if((Math.abs( time -timestamp) >1000 * 60 *5){
- return false;
- }
- return true;
- }catch (Exception e){
- return false;
- }
- }
- }
|