1,%u格式解码 unicode
string = string.replace("%", “\”);
String url2Condition = “\\u[^%]{4}”;
Matcher field2Matcher = Pattern.compile(url2Condition).matcher(string);
while (field2Matcher.find()) {
String value = field2Matcher.group();
string = string.replace(value, decodeUnicode(value));
}
private String decodeUnicode(String dataStr) {
int start = 0;
int end;
final StringBuilder buffer = new StringBuilder();
while (start > -1) {
end = dataStr.indexOf("\u", start + 2);
String charStr;
if (end == -1) {
charStr = dataStr.substring(start + 2);
} else {
charStr = dataStr.substring(start + 2, end);
}
char letter = (char) Integer.parseInt(charStr, 16); // 16进制parse整形字符串。
buffer.append(letter);
start = end;
}
return buffer.toString();
}
2,url解码
String urlCondition = “%[^u].(?!%)”;
Matcher fieldMatcher = Pattern.compile(urlCondition).matcher(string);
while (fieldMatcher.find()) {
String value = fieldMatcher.group();
string = string.replaceAll(value, URLDecoder.decode(value, “utf-8”));
}
3,url编码
string = string.replace(str, URLEncoder.encode(str, “utf-8”);
4,bs64 解码
Base64.Decoder decoder = Base64.getDecoder();
String result = new String(decoder.decode(data));
5,bs64编码
String index = “”;
Base64.Encoder encoder = Base64.getEncoder();
String s = encoder.encodeToString(index.getBytes());
System.out.println(“加密:” + s);