1, the role of BASE64
is primarily not encryption, its main purpose is to convert some binary numbers into ordinary characters for network transmission.
since some binary characters belong to the control characters in the transport protocol, they cannot be transferred directly.
2, how to get BASE64 code, there are two ways
One way: solve the problem of not using base64encoder directly in Eclipse
- Today to use Base64encoder, but found in eclipse can not find the class, Google ha, originally Base64encoder is not the JDK standard library category, but also included in the JDK.
- Workaround: Set the Rt.jar package under Eclipse import%java_home%\jre\lib directory as follows,project->properties, select the JAVA Build path setting, Then select the libraries tag,
- Add External jars added%java_home%\jre\lib\rt.jar can be used!
mode two: Download the source code, and then import the code into your own project
csdn:http://download.csdn.net/detail/yanzi2015/8685199
3. BASE64 encoding and decoding of strings
Package Com.android20;import Sun.misc.BASE64Decoder; Public classBian {//encode s for BASE64 Public Staticstring getBASE64 (string s) {if(s = =NULL)return NULL; return(NewSun.misc.BASE64Encoder ()). Encode (S.getbytes ()); } //decodes a BASE64 encoded string s Public Staticstring getFromBASE64 (string s) {if(s = =NULL)return NULL; Base64decoder Decoder=NewBase64decoder (); Try { byte[] B =Decoder.decodebuffer (s); return NewString (b); } Catch(Exception e) {return NULL; } }}
Android Java BASE64 encoding and decoding