URLencode、URLdecode
// 将application/x-www-from-urlencoded字符串转换成普通字符串
String keyWord = URLDecoder.decode("%E4%BD%A0%E5%A5%BD", "utf-8");
System.out.println(keyWord); //输出你好
// 将普通字符创转换成application/x-www-from-urlencoded字符串
String urlString = URLEncoder.encode("你好", "utf-8"); //输出%E4%BD%A0%E5%A5%BD
System.out.println(urlString);
在线地址:
http://tool.chinaz.com/tools/urlencode.aspx
Base64加解密
Base64 base64 = new Base64();
String encodeText = base64.encodeToString("123456");//加密
String decodeText = base64.decode(encodedText), "UTF-8");//解密
在线地址:
https://base64.us/
高效方法:
final Base64.Decoder decoder = Base64.getDecoder();
final Base64.Encoder encoder = Base64.getEncoder();
final String text = "字串文字";
final byte[] textByte = text.getBytes("UTF-8");
//编码
final String encodedText = encoder.encodeToString(textByte);
System.out.println(encodedText);
//解码
System.out.println(new String(decoder.decode(encodedText), "UTF-8"));
参考:
https://blog.youkuaiyun.com/iamlihongwei/article/details/97793114