BASE64 Coding algorithm

Source: Internet
Author: User
Tags base64

Reprint: http://www.cnblogs.com/xqxacm/p/4886299.html

First, what is encoded decoding

Coding: The use of specific algorithms, the original content processing, generate the operation of the content, the formation of another form of data, can be based on the algorithm, and then restore back, this operation is called coding.

Decoding: Using the inverse operation of the algorithm used by the code, processing the encoded data, and restoring the original data, this operation is called decoding.

Second, what is the Base64 coding algorithm

Arbitrary byte array data can be generated by an algorithm that generates only the string data represented by (in the case of English, numeric, +,/) (64 characters).

Converts an arbitrary content into a visible string form.

Three, the origin of Base64 algorithm

Previously sent messages only support the delivery of visible characters. Thus, there is a need for a method to convert invisible characters to visible characters, resulting in the BASE64 encoding algorithm

Iv. Features of Base64 algorithm

1. The data is processed in the form of 3 bytes, and every three bytes are converted to 4 bytes after encoding.

That is, if a data has 6 bytes, it will be encoded with 6/3*4=8 bytes

2, when the length of the data can not meet a multiple of 3, the final data needs to fill the operation, that is, fill "=", where "=" is a fill character, do not understand as the 65th character

Eg: three bytes, converted to 4 bytes of the process:

  

As you can see, each of the three bytes of raw data is divided into a set of bits, divided into a byte per 6 bits, converted to form a new 4 bytes. These four bytes are mapped by the BASE64 encoding table, resulting in the final actual Base64 encoding.

If the original data cannot be made up to 3 bytes at the end, the fill is replaced with "=", which means there is no data

Five

BASE64 Coded Index Table

Vi. Base64 Usage Scenarios

1. The server passes binary data to the client in JSON

2, the client passes the parameter to the server, passes the binary content through the BASE64

Seven, the attention point

1, Base64 is a coding algorithm, not a cryptographic algorithm, just used to encode a byte array, form a string, and provide a decoding function

2, Base64.encodetostring (byte[] data,int flag);

The second parameter setting No_wrap means that the resulting string is wrapped.

Base64.encode (String str,int flag) Ibid.

BASE64 Coding algorithm

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.