使用base64编码的好处
在项目中,将报文进行压缩、加密后,最后一步必然是使用base64编码,因为base64编码的字符串,更适合不同平台、不同语言的传输;
它不受其他编码的影响,仍然保持不变,这点很有意义,如下验证:
String a = "123412312sfwefwefwefw";
String b = new String(CodecManager.getCodecClient(CodecConstants.BASE64).encode(a.getBytes()));
System.out.println(b);
//对base64编码后的字符串,进行其他编码
String c1 = new String(b.getBytes(),"gbk");
System.out.println(c1);
String c2 = new String(b.getBytes(),"utf-8");
System.out.println(c2);
String c3 = new String(b.getBytes(),"ISO8859-1");
System.out.println(c3);
输出:
MTIzNDEyMzEyc2Z3ZWZ3ZWZ3ZWZ3
MTIzNDEyMzEyc2Z3ZWZ3ZWZ3ZWZ3
MTIzNDEyMzEyc2Z3ZWZ3ZWZ3ZWZ3
MTIzNDEyMzEyc2Z3ZWZ3ZWZ3ZWZ3