Java Encryption Framework Base64

Source: Internet
Author: User
Tags base64 binary to decimal rfc

A paragraph of text after BASE64 encoding after recognition, and after Base64 decoding can be restored. This is very much a cryptographic decryption of the meaning. However, the BASE64 algorithm is not a cryptographic algorithm, and the conversion of BASE64 algorithm is much like the single-table permutation algorithm in classical encryption algorithm.
The BASE64 algorithm was first used to resolve message transmission problems. Only ASCII characters are allowed in early e-mail. Non-ASCII characters can be transmitted with a problem, so Base64 encoding occurs.
Base64 is a 64-character encoding algorithm. After BASE64 encoded data will be slightly longer than the original data, 4/3 times the original. The number of characters of the BASE64 encoded string is an integer multiple of 4.

In this mapping table, value is a decimal code and Encoding is a character. A total of 64 characters are mapped. The last =, is the permanent complement.
BASE64 has 2 specifications: RFC 2045: Specify 76 characters per line, add a carriage return line at the end of each line, even if the last line is not enough 76 characters, but also add line character RFC 4648: No Line-break
Base64 also has several similar algorithms, such as BASE32,BASE16. In order to be able to transmit binary data in HTTP in a get way, the URL Base64 is also derived.
The URL Base64 algorithm replaces the 62nd and 63 characters in the BASE64 mapping table as long as it is replaced. Replace + Replace with-,/to _. For the complement number =, the bouncy Castle is used. Make a placeholder. Commons Codec does not use a placeholder.
The BASE64 algorithm has encoding and decoding operations that can act as cryptographic and decoding operations. Can be used for simple encryption. But realize that Base64 can not be considered as an encryption algorithm. Base64 commonly used to do key, ciphertext and certificate of a common storage encoding format.


BASE64 encoded operation: 1 converts the given string in characters to the corresponding character encoding 2 converts the character encoding to binary 3 to the obtained binary to do the grouping conversion operation: every 3 8-bit binary code is a group, converted to a group of 4 bits of binary code (less than 6 bits when the low-bit 6) 0 4-6 binary code complement, high-2 0, composed of 4 8-bit binary 5 convert 4-8 binary to decimal 6 to get the corresponding characters through the mapping table, not enough 4 sets of complement =

From jdk1.8 onwards, Java provides a BASE64 implementation that can be used directly with java.util.Base64. Prior to jdk1.8, Java did not provide a public BASE64 implementation (internally implemented in the Sun.misc package), typically implemented by itself, or by referencing the COMMONS-CODEC package
Strings ="Base64is the most common on the network for transport8Bitone of the encoding methods of the byte code";byte[] b = s.getbytes ("UTF-8");byte[] out =java.util.Base64.Getencoder(). Encode (b);System. out. println (NewString (out));java.util.Base64.Getmimeencoder(). Encode (b);System. out. println (NewString (out));java.util.Base64.Geturlencoder(). Encode (b);System. out. println (NewString (out));



Java Encryption Framework Base64

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.