update 对外接口的加解密
This commit is contained in:
@@ -1,78 +1,84 @@
|
||||
//package com.jero.modules.iam;
|
||||
//import com.banboocloud.Codec.BamboocloudFacade;
|
||||
//import com.ruoyi.common.utils.reflect.ReflectUtils;
|
||||
//import org.slf4j.Logger;
|
||||
//import org.slf4j.LoggerFactory;
|
||||
//
|
||||
//import javax.servlet.http.HttpServletRequest;
|
||||
//import java.io.BufferedReader;
|
||||
//import java.io.IOException;
|
||||
//import java.util.Iterator;
|
||||
//import java.util.Map;
|
||||
//import java.util.TreeMap;
|
||||
//public class BamboocloudUtils {
|
||||
// private static Logger logger = LoggerFactory.getLogger(ReflectUtils.class);
|
||||
// public static boolean checkUsernamePassword(String username, String password) {
|
||||
// logger.info("username --->" + username + " password --- >" + password + " ----ok");
|
||||
// if("bbcadmin".equals(username)&&"P@ssw0rd".equals(password)) {
|
||||
// return true;
|
||||
// }
|
||||
// else {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public static String getPlaintext(String ciphertext, String key, String type) {
|
||||
// return BamboocloudFacade.decrypt(ciphertext, key, type);
|
||||
// }
|
||||
//
|
||||
// public static Boolean verify(Map<String, Object> reqmap, String type) {
|
||||
// Map<String, Object> verifymap = new TreeMap<String, Object>();
|
||||
// StringBuffer sb = new StringBuffer();
|
||||
// Iterator<String> it = reqmap.keySet().iterator();
|
||||
// while (it.hasNext()) {
|
||||
// String key = (String) it.next();
|
||||
// verifymap.put(key, reqmap.get(key));
|
||||
// }
|
||||
// Iterator<String> ittree = verifymap.keySet().iterator();
|
||||
// while (ittree.hasNext()) {
|
||||
// String key = (String) ittree.next();
|
||||
// if (!"signature".equals(key)) {
|
||||
// sb.append(key).append("=").append(verifymap.get(key)).append("&");
|
||||
// }
|
||||
// }
|
||||
// sb.deleteCharAt(sb.length() - 1);
|
||||
// System.out.println(reqmap.get("signature") + " now " + sb.toString());
|
||||
// return BamboocloudFacade.verify(reqmap.get("signature").toString(), sb.toString(), type);
|
||||
// }
|
||||
//
|
||||
// public static String getRequestBody(HttpServletRequest request) {
|
||||
// BufferedReader br = null;
|
||||
// StringBuilder sb = new StringBuilder();
|
||||
// String str = "";
|
||||
// try {
|
||||
// br = request.getReader();
|
||||
// while ((str = br.readLine()) != null) {
|
||||
// sb.append(str);
|
||||
// }
|
||||
// br.close();
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// if (br != null)
|
||||
// try {
|
||||
// br.close();
|
||||
// } catch (IOException eo) {
|
||||
// eo.printStackTrace();
|
||||
// }
|
||||
// } finally {
|
||||
// if (br != null) {
|
||||
// try {
|
||||
// br.close();
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return sb.toString();
|
||||
// }
|
||||
//}
|
||||
package com.jero.modules.iam;
|
||||
|
||||
import com.bamboocloud.codec.BamboocloudFacade;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
@Slf4j
|
||||
public class BamboocloudUtils {
|
||||
public static void main(String[] args) {
|
||||
String aes = BamboocloudFacade.encrypt("{\"uid\":\"104\",\"bimRequestId\":\"95d73fe7aa7a4930a3edea779708a46c\",\"resultCode\":\"0\",\"message\":\"success\"}", "123456", "AES");
|
||||
System.out.println(aes);
|
||||
String aes1 = getPlaintext("KJ3jbIflWkNiEq3oxE2d5oxtKRLO3CC7edGrq57RIB02RSRgPljiNcTfuWYLS3sc1tbZMLm5fWG2guLK100g9MkWH9NhlxorPSlcP8LaYuP5NeZ1wFP8iKqr5RredwXfDA3J1fjOCAJfzPvJ4HSb1w==", "123456", "AES");
|
||||
System.out.println(aes1);
|
||||
}
|
||||
public static boolean checkUsernamePassword(String username, String password) {
|
||||
log.info("username --->" + username + " password --- >" + password + " ----ok");
|
||||
if("bbcadmin".equals(username)&&"P@ssw0rd".equals(password)) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getPlaintext(String ciphertext, String key, String type) {
|
||||
return BamboocloudFacade.decrypt(ciphertext, key, type);
|
||||
}
|
||||
|
||||
public static Boolean verify(Map<String, Object> reqmap, String type) {
|
||||
Map<String, Object> verifymap = new TreeMap<String, Object>();
|
||||
StringBuffer sb = new StringBuffer();
|
||||
Iterator<String> it = reqmap.keySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
String key = (String) it.next();
|
||||
verifymap.put(key, reqmap.get(key));
|
||||
}
|
||||
Iterator<String> ittree = verifymap.keySet().iterator();
|
||||
while (ittree.hasNext()) {
|
||||
String key = (String) ittree.next();
|
||||
if (!"signature".equals(key)) {
|
||||
sb.append(key).append("=").append(verifymap.get(key)).append("&");
|
||||
}
|
||||
}
|
||||
sb.deleteCharAt(sb.length() - 1);
|
||||
System.out.println(reqmap.get("signature") + " now " + sb.toString());
|
||||
return BamboocloudFacade.verify(reqmap.get("signature").toString(), sb.toString(), type);
|
||||
}
|
||||
|
||||
public static String getRequestBody(HttpServletRequest request) {
|
||||
BufferedReader br = null;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String str = "";
|
||||
try {
|
||||
br = request.getReader();
|
||||
while ((str = br.readLine()) != null) {
|
||||
sb.append(str);
|
||||
}
|
||||
br.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
if (br != null) {
|
||||
try {
|
||||
br.close();
|
||||
} catch (IOException eo) {
|
||||
eo.printStackTrace();
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (br != null) {
|
||||
try {
|
||||
br.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,52 +1,42 @@
|
||||
//package com.jero.modules.iam;
|
||||
//import com.alibaba.fastjson.JSON;
|
||||
//import com.alibaba.fastjson.JSONObject;
|
||||
//import com.banboocloud.Codec.BamboocloudFacade;
|
||||
//import com.ruoyi.common.utils.reflect.ReflectUtils;
|
||||
//import com.ruoyi.framework.web.controller.BaseController;
|
||||
//import com.ruoyi.project.system.dept.domain.Dept;
|
||||
//import com.ruoyi.project.system.dept.service.IDeptService;
|
||||
//import com.ruoyi.project.system.dict.domain.DictData;
|
||||
//import com.ruoyi.project.system.dict.service.IDictDataService;
|
||||
//import com.ruoyi.project.system.post.domain.Post;
|
||||
//import com.ruoyi.project.system.post.service.IPostService;
|
||||
//import com.ruoyi.project.system.role.domain.Role;
|
||||
//import com.ruoyi.project.system.role.service.IRoleService;
|
||||
//import com.ruoyi.project.system.user.domain.User;
|
||||
//import com.ruoyi.project.system.user.domain.UserRole;
|
||||
//import com.ruoyi.project.system.user.service.IUserService;
|
||||
//import com.ruoyi.project.tool.swagger.accessory.*;
|
||||
//import io.swagger.annotations.Api;
|
||||
//import io.swagger.annotations.ApiImplicitParam;
|
||||
//import io.swagger.annotations.ApiOperation;
|
||||
//import org.slf4j.Logger;
|
||||
//import org.slf4j.LoggerFactory;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.web.bind.annotation.PostMapping;
|
||||
//import org.springframework.web.bind.annotation.RequestMapping;
|
||||
//import org.springframework.web.bind.annotation.ResponseBody;
|
||||
//import org.springframework.web.bind.annotation.RestController;
|
||||
//
|
||||
//import javax.servlet.ServletException;
|
||||
//import javax.servlet.http.HttpServletRequest;
|
||||
//import javax.servlet.http.HttpServletResponse;
|
||||
//import java.io.BufferedReader;
|
||||
//import java.io.IOException;
|
||||
//import java.io.PrintWriter;
|
||||
//import java.util.*;
|
||||
package com.jero.modules.iam;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import com.bamboocloud.codec.BamboocloudFacade;
|
||||
import com.jero.modules.system.service.ISysDepartService;
|
||||
import com.jero.modules.system.service.ISysRoleService;
|
||||
import com.jero.modules.system.service.ISysUserService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.*;
|
||||
//public class BbcController {
|
||||
//
|
||||
// @Autowired
|
||||
// private IUserService userService;
|
||||
// private ISysUserService userService;
|
||||
//
|
||||
// @Autowired
|
||||
// private IRoleService roleService;
|
||||
// private ISysRoleService roleService;
|
||||
//
|
||||
// @Autowired
|
||||
// private IPostService postService;
|
||||
//
|
||||
// @Autowired
|
||||
// private IDeptService deptService;
|
||||
// private ISysDepartService deptService;
|
||||
//
|
||||
// @Autowired
|
||||
// private IDictDataService dictDataService;
|
||||
@@ -56,7 +46,7 @@
|
||||
//
|
||||
// private String bimRequestId;
|
||||
//
|
||||
// private static Logger logger = LoggerFactory.getLogger(ReflectUtils.class);
|
||||
// private static Logger logger = LoggerFactory.getLogger(BbcController.class);
|
||||
//
|
||||
// @ApiOperation("测试")
|
||||
// @RequestMapping()
|
||||
|
||||
@@ -5,7 +5,10 @@ import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
public class SHA256Util {
|
||||
|
||||
public static void main(String[] args) {
|
||||
String sha256StrJava = getSHA256StrJava("123456");
|
||||
System.out.println(sha256StrJava);
|
||||
}
|
||||
/**
|
||||
* 利用java原生的摘要实现SHA256加密密后的报文
|
||||
*/
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user