Android Java BASE64 encoding and decoding

Source: Internet
Author: User
Tags control characters

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.