Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Base64 coding

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

Base64. As the name implies, it is a way to represent binary data based on 64 printable characters. (it is not an encryption algorithm). For 64 printed characters, we need 6 binary bits to fully represent the word. So how do we use eight binary bits to represent printable characters that can be fully represented by only six binary bits? Since the sixth power of 2 equals 64, we can divide every six bits into a unit that corresponds to a printable character. Three bytes have 24 bits, corresponding to four Base64 units, that is, three bytes need to be represented by four printable characters. It can be used as the transmission code of e-mail. Printable characters in Base64 include the letters Amurz, Amurz, and the numbers 0-9, so there are a total of 62 characters, in addition to two printable symbols that vary from system to system.

Base64 index table: (original table)

Example of coding process:

Coding

The top three bytes are the original text, and the next four bytes are converted Base64 encodings, with the first two bits 0.

After conversion, we get the string we want (that is, the final Base64 encoding) by converting the binary to printable characters.

We can see that after base64 encoding, the string is theoretically longer than before, that is, the original 4ax 3. (except for the following two cases).

If the number of bytes to be encoded is not divisible by 3, resulting in an extra 1 or 2 bytes, you can use the following method: use the 0 byte value at the end to make it divisible by 3, and then encode base64. Add one or two'= 'signs to the encoded base64 text to represent the number of bytes to be filled. In other words, when the last octet (one byte) is left, the last 6-bit base64 byte block has four bits of zero value, followed by two equal signs; if the last two octets (2 byte) are left, the last 6-bit base byte block has two bits of zero value, followed by an equal sign.

There is usually an = sign after base64 coding, and the longer ciphertext length is basically base64 coding. (the length of the base64 code is not fixed) (the equal sign is the result of modifying 64 printable characters depending on usage.)

Application of base64

Base64 online Decoding: http://www1.tc711.com/tool/BASE64.htm

Https://zh.wikipedia.org/zh/Base64

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report