Encoding principle _ base64 encoding Principle

Source: Internet
Author: User
Tags printable characters

 

1.1 base64 Encoding Principle 1.1.1 Summary :

Base64 is a common encoding method in communication transmission.

(Note the encoding algorithm, not the encryption algorithm)

A common problem occurs during parameter transmission: Garbled characters are not involved in the use of English letters, however, if other languages are involved, garbled characters may occur, and the characters transmitted over the network are not all printable characters, such as videos and images.

Base64 is used to solve this problem. It represents binary data based on 64 printable characters.

When an email appears, it can only be transmitted in English. However, as the number of users increases, the number of Chinese and Japanese characters increases, but the characters cannot be effectively processed by the server or gateway, therefore, base64 is displayed. Base64 is also used for URL, cookie, and webpage transmission of a small amount of binary files.

1.1.2 Encoding Principle :

We all know that computer data is stored in bytes, and a byte is composed of eight bits. Each bit is the smallest unit of information.

So1 byte = 8bit

(In this article, byte is used as the unit of measurement for computing storage capacity.

ByteIt is also an unsigned data type. The value ranges from 0 to 255 and cannot be negative. But it is not covered in the scope of this article .)

Step 1: divide each three bytes of the string to be converted into one group. Each byte occupies 8 bits, and there are 24 binary digits in total.

Step 2: divide each of the preceding 24 binary bits into six groups.

Step 3: Add two zeros in front of each group. Each group is changed from 6 to 8 binary bits. A total of 32 binary bits are four bytes.

Step 4: obtain the corresponding value based on the base64 encoding table.

For example:

1.1.3 Program functions

Programming

Python built-in base64 can be directly used for base64 encoding and decoding.

 

 

Related functions are also available in PHP.

base64_encode()base64_decode(string data)

  

Java contains the org. Apache. commons. codec. Binary. base64 class.

 

 

 

 

Encoding principle _ base64 encoding Principle

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.