Application of Base64 encoding in PHP

Source: Internet
Author: User
Tags mozilla thunderbird
Base64 is one of the most common encoding methods used to transmit 8-bit code on the network. For details, refer to RFC2045 ~ RFC2049, which has the MIME detailed specification. Base64 encoding can be used to transmit long identification information in the HTTP environment. For example, in the JavaPersistence system Hibernate, Base64 is used to set a long unique identifier (

Base64 is one of the most common encoding methods used to transmit 8-bit code on the network. For details, refer to RFC2045 ~ RFC2049, which has the MIME detailed specification. Base64 encoding can be used to transmit long identification information in the HTTP environment. For example, in Java Persistence system Hibernate, Base64 is used to set a long unique identifier (

Base64 is one of the most common encoding methods used to transmit 8-bit code on the network. For details, refer to RFC2045 ~ RFC2049, which has the MIME detailed specification. Base64 encoding can be used to transmit long identification information in the HTTP environment. For example, in Java Persistence system Hibernate, Base64 is used to encode a long unique identifier (generally 128-bit UUID) into a string, used as parameters in HTTP forms and http get URLs. In other applications, binary data is often encoded in a URL (including hidden form fields) format. At this time, Base64 encoding is not only short, but also non-readable, that is, the encoded data is not directly seen by the human eye.


The standard Base64 is not suitable for direct transmission in the URL, because the URL encoder will convert the "/" and "+" characters in the standard Base64 into the form of "% XX, these "%" signs need to be converted when they are stored in the database, because "%" has been used as a wildcard in ansi SQL. To solve this problem, you can use an improved Base64 encoding for the URL, which does not fill the '=' sign at the end, the "+" and "/" in the standard Base64 are changed to "*" and "-" respectively, thus eliminating the need for conversion during URL encoding/decoding and database storage, this avoids the increase in the length of the encoding information during this process, and unifies the format of object identifiers in databases, forms, and other places. There is also an improved Base64 variant for regular expressions. It changes "+" and "/" to "!". And "-", because "+", "*", and "[" and "]" previously used in IRCu may have special meanings in regular expressions. There are also some variants that change "+/" to "_-" or ". _ "(used as the identifier name in the programming language) or". -"(used for Nmtoken in XML) or even" _: "(used for Name in XML ). Base64 requires that each three 8-bit bytes be converted into four 6-bit bytes (3*8 = 4*6 = 24), and then 6-bit bytes be added with two more high 0 values, it consists of four 8-bit bytes. That is to say, the converted string is theoretically 1/3 longer than the original one.


Mozilla Thunderbird and Evolution use Base64 to keep Email passwords confidential

Base64 is often used as a simple "encryption" to protect some data, and real encryption is usually cumbersome.

Spam message disseminators use Base64 to avoid anti-spam tools, because these tools usually do not translate Base64 messages.

In the LDIF file, Base64 is used as the encoding string.

Taking "Thunder download" as an example: Many download websites provide the "Thunder download" link. The address is usually dedicated to encrypted thunder. For example, thunder: // QUFodHRwOi8vd3d3LmJhaWR1LmNvbS9pbWcvc3NsbTFfbG9nby5naWZaWg = In fact, thunder's "dedicated address" is also encrypted with Base64. The encryption process is as below: 1. add AA and ZZ respectively before and after the address, for example, www.baidu.com/img/sslm?logo.gif to rewrite 2, encode the new string with Base64, for example, encoding 3, and add "thunder: "thunder: // QUF3d3cuYmFpZHUuY29tL2ltZy9zc2xtMV9sb2dvLmdpZlpa" is similar to thunder, but the "material" added in the first step is different, the "material" That Flashget adds before and after the address is [FLASHGET], while the QQ tornado simply does not add the material, and the address is base64-encoded.

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.