BASE64 Coding Rules

Source: Internet
Author: User
Tags base64

The Base64 encoding rule is a method that uses 64 characters to represent any binary data.
Usually use Notepad to open exe, JPG, PDF of these files, we will see a lot of garbled, because the binary file contains many characters can not be displayed and printed, so if you want to make Notepad such a text processing software processing binary data, you need a binary to string conversion method. Base64 is one of the most common binary encoding methods.

The BASE64 principle is simple:
1. First, prepare an array containing 64 characters
[' A ', ' B ', ' C ', ... ' A ', ' B ', ' C ', ... ' 0 ', ' 1 ', ... ' + ', '/']
2. Then, the binary data is processed, every 3 bytes a group, altogether is 3x8=24bit, is divided into 4 groups, each group exactly 6 bit:

Base64-encode
So we get 4 numbers as index, then look up the table, get the corresponding 4 characters, is the encoded string.
3. Therefore, the BASE64 encoding will encode 3 bytes of binary data into 4 bytes of text data, the length of 33%, the advantage is that the encoded text data can be displayed directly in the message body, Web pages and so on.
4. If the binary data you want to encode is not a multiple of 3, there will be 1 or 2 bytes left in the end. Base64 with \x00 bytes at the end of the top, and then at the end of the code to add 1 or 2 = number, indicating how many bytes were filled, decoding, will be automatically removed.

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.