Java Urlencoder and Base64.encode ()

Source: Internet
Author: User

Reference:

Http://www.360doc.com/content/10/1103/12/1485725_66213001.shtml (urlencode)

http://blog.csdn.net/uikoo9/article/details/27981219

The data in the computer is binary, whether it is a string or a file, and the encryption is binary,

What we want to see is often a string, this article describes the conversion of byte[] into a variety of binary and Base64 Encoding.

is a coding method, can be understood as a complex binary, many algorithms are encrypted after the output is byte[], and this byte[] the form we show is not friendly (garbled),

So it is generally converted to base64, and of course can be converted into other systems.

public static void main (string[] S) {
String sss = "AA123AA program";
byte[] bytes = null;
try {
bytes = Sss.getbytes ("UTF-8");
For (byte b:bytes) {
System.out.print (b + "(#)");
}
} catch (unsupportedencodingexception E) {
E.printstacktrace ();
}


String encode;
try {

encode = Base64.encode (bytes);
System.out.println ("\nbase64.encode result:" + encode);
byte[] bytess = Base64.decode (encode);
For (byte B:bytess) {
System.out.print (b + "(#)");
}
String sss2 = new string (bytess, "UTF-8");
System.out.print ("\nsss2 = = =" + sss2);

SSS = "Aa123 AA Program # program * Program +and program";
encode = Java.net.URLEncoder.encode (sss, "UTF-8");
System.out.println ("\njava.net.urlencoder result:" + encode);
String SSS3 = Urldecoder.decode (encode, "UTF-8");
System.out.println ("\njava.net.urldecoder result:" + sss3);
} catch (Exception E) {
E.printstacktrace ();
}

Operation Result:

65 (#) 97 (#) 49 (#) 50 (#) 51 (#) 65 (#) 97 (#)-25 (#)-88 (#)-117 (#)-27 (#)-70 (#)-113 (#)
Base64.encode results: qwexmjnbyeeoi+w6jw==
65 (#) 97 (#) 49 (#) 50 (#) 51 (#) 65 (#) 97 (#)-25 (#)-88 (#)-117 (#)-27 (#)-70 (#)-113 (#)
Sss2 = = = AA123AA Program
Java.net.URLEncoder results: aa123+aa%e7%a8%8b%e5%ba%8f%23%e7%a8%8b%e5%ba%8f*%e7%a8%8b%e5%ba%8f%2band%e7%a8%8b%e5%ba% 8F

Java.net.URLDecoder results: Aa123 AA Program # program * Program +and Program

Java Urlencoder and Base64.encode ()

Related Article

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.