PHP JAVA BASE64 encode decode

注意所有编码都是 UTF8 编码
JAVA 1.8 +
JAVA 11 +
风.foxwho

java Base64 encoder

String tmp = "A1234好.123~!@#$%^*&(";
System.out.println(tmp);
System.out.println(Base64.getEncoder().encodeToString(tmp.getBytes())); 
输出:
QTEyMzTlpb0uMTIzfiFAIyQlXiomKA==

php base64 encode

$str = "A1234好.123~!@#$%^*&(";
echo base64_encode($str);
输出:
QTEyMzTlpb0uMTIzfiFAIyQlXiomKA==

java base64 decode

 String tmp2 = "QTEyMzTlpb0uMTIzfiFAIyQlXiomKA==";
 String result = "";
 try {
     result = new String(Base64.getDecoder().decode(tmp2), "UTF-8");
 } catch (Exception $e) {

 }
 // A1234好.123~!@#$%^*&(
 System.out.println(result);
 结果:
 A1234好.123~!@#$%^*&(

php base64 decode

$str = "QTEyMzTlpb0uMTIzfiFAIyQlXiomKA==";
echo base64_decode($str);
结果:
A1234.123~!@#$%^*&(

你可能感兴趣的:(PHP,java,php,java,base64)