标签:[] https else 总结 信息 echo get match string
例如:
字符串:RGFqaURhbGlfSmlud2FuQ2hpamk=
首先要知道什么是Base64加密?就是Base64是怎么加密的?
Base64编码是从二进制到字符的过程,可用于在HTTP环境下传递较长的标识信息
至于Base64是怎么加密的?
看一个简单的例子:
1 private static boolean isBase64(String str) {
2 String base64Pattern = "^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)$";
3 return Pattern.matches(base64Pattern, str);
4 }
Java代码判断
1 private static boolean isBase64(String str) {
2 if (str == null || str.trm().length() == 0) {
3 return false;
4 } else {
5 if (str.length() % 4 != 0) {
6 return false;
7 }
8
9 char[] strChars = str.toCharArray();
10 for (char c:strChars) {
11 if ((c >= ‘a‘ && c <= ‘z‘) || (c >= ‘A‘ && c <= ‘Z‘) || (c >= ‘0‘ && c <= ‘9‘)
12 || c == ‘+‘ || c == ‘/‘ || c == ‘=‘) {
13 continue;
14 } else {
15 return false;
16 }
17 }
18 return true;
19 }
20 }
PHP代码判断
$s = "RGFqaURhbGlfSmlud2FuQ2hpamk=";
if ($s == base64_encode(base64_decode($s))) {
echo ‘yes‘;
}else{
echo ‘no‘;
希望对大家理解Base64有所帮助。
标签:[] https else 总结 信息 echo get match string
原文地址:https://www.cnblogs.com/liuzeyu12a/p/9902769.html