| | |
| | | return null; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * RSA验签名检查 |
| | | * @param params 所有参数 |
| | | * @param publicKey 分配给开发商公钥 |
| | | * @param encode 字符集编码 |
| | | * @return 布尔值 |
| | | */ |
| | | public static boolean doCheck(Map<String,String> params, String publicKey, String encode) { |
| | | String sign = params.get("sign"); |
| | | if(sign == null){ |
| | | return false; |
| | | } |
| | | String content = getSignCheckContent(params); |
| | | return doCheck( content, sign, publicKey, encode); |
| | | } |
| | | |
| | | public static String getSignCheckContent(Map<String, String> params) { |
| | | if (params == null) { |
| | | return null; |
| | | } else { |
| | | params.remove("sign"); |
| | | StringBuilder content = new StringBuilder(); |
| | | List<String> keys = new ArrayList(params.keySet()); |
| | | Collections.sort(keys); |
| | | |
| | | for(int i = 0; i < keys.size(); ++i) { |
| | | String key = (String)keys.get(i); |
| | | String value = (String)params.get(key); |
| | | if(StringUtils.isEmpty(value)){ |
| | | continue; |
| | | } |
| | | content.append(i == 0 ? "" : "&").append(key).append("=").append(value); |
| | | } |
| | | return content.toString(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * RSA验签名检查 |
| | | * @param content 待签名数据 |
| | |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * ASCII码递增排序(剔除空值) |
| | | * @param params |
| | | * @return |
| | | */ |
| | | public static String getSignCheckContent(Map<String, String> params) { |
| | | if (params == null) { |
| | | return null; |
| | | } else { |
| | | StringBuilder content = new StringBuilder(); |
| | | List<String> keys = new ArrayList(params.keySet()); |
| | | Collections.sort(keys); |
| | | |
| | | for(int i = 0; i < keys.size(); ++i) { |
| | | String key = (String)keys.get(i); |
| | | Object value = params.get(key); |
| | | if(value == null || StringUtils.isEmpty(value.toString())){ |
| | | continue; |
| | | } |
| | | content.append(i == 0 ? "" : "&").append(key).append("=").append(value); |
| | | } |
| | | return content.toString(); |
| | | } |
| | | } |
| | | |
| | | } |