base64加密
楼主在对接硬件设备的时候,设备传参是用base64加密的,所以需要解密,但是没有设备,所以需要用postman模拟设备传参,结果在加密解密的过程中出现了很睿智的一幕…
加密的时候是在网站上加密的,没错就是百度-,-参数拿到了,用代码解密,如下
private String base64Decoder(ZhuoWenParamsModel zhuoWenParamsModel) throws IOException {
if (zhuoWenParamsModel == null) return null;
/*解析数据*/
String contentBase64 = zhuoWenParamsModel.getContent();
Base64 base64 = new Base64();
byte[] decode = base64.decode(contentBase64);
return new String(decode, "utf-8");
}
打印一下返回结果,出现了这么个玩意
%7B%0A%09%22autoid%22%3A%201%2C%0A%09%22mac%22%3A%20%22187ED53162E0%22%2C%0A%09%22datetime%22%3A%20%222019-11-12%2012%3A00%3A00%22%2C%0A%09%22title%22%3A%20%22%u7EBF%u8DEF1%22%2C%0A%09%22addr%22%3A%20%221%22%2C%0A%09%22type%22%3A%20%22%u544A%u8B66%22%2C%0A%09%22info%22%3A%20%22%u6D4B%u8BD5%u62A5%u8B66%22%2C%0A%09%22is_del%22%3A%20%22Y%22%2C%0A%09%22is_sync%22%3A%20%22Y%22%2C%0A%09%22alarm_number%22%3A%201%0
搞了两个小时各种编码转来转去,最后问了下前辈,可能是网站的加密方式和代码的解密方式不一样,用代码加密再用代码解密就OK了…
加密代码
@Test
public void encode(){
String str="31231sfdfrqw3r23ewrqwr23";
byte[] bytes=str.getBytes();
String base64keyString =new BASE64Encoder().encodeBuffer(bytes);
System.out.println(base64keyString);
}
真是醉了…