Home  >  Article  >  What is the use of base64 encoding?

What is the use of base64 encoding?

coldplay.xixi
coldplay.xixiOriginal
2020-07-01 15:07:077153browse

The uses of base64 encoding: 1. Convert non-ASCII character data into ASCII characters; 2. Especially suitable for fast data transmission under http and mime protocols; 3. The data content is encoded for transmission, which is safe and simple .

What is the use of base64 encoding?

Use of base64 encoding:

1. Function of Base64

  • Because only ASCII characters can be used in some systems. Base64 is a method used to convert non-ASCII character data into ASCII characters.

  • base64 is particularly suitable for fast data transmission under http and mime protocols.

  • base64 is actually not an encryption and decryption algorithm in the security field. Although sometimes we often see so-called base64 encryption and decryption. In fact, base64 can only be regarded as an encoding algorithm, encoding the data content to suit transmission. Although the original text becomes an invisible character format after base64 encoding, this method is very elementary and simple.

##2. Base64 encoding application

Base64 encoding can be used to transmit longer identification information in the

HTTP environment. For example, in Java Persistence systemHibernate, Base64 is used to encode a longer unique identifier (usually a 128-bit UUID) into a string, using Make parameters in HTTP form and HTTP GET URL. In other applications, it is often necessary to encode binary data into a form suitable for placement in a URL (including hidden form fields). At this time, using Base64 encoding is not only shorter, but also unreadable, that is, the encoded data will not be directly visible to the naked eye.

However, standard Base64 is not suitable for transmission directly in the URL, because the URL encoder will change the "/" and " " characters in standard Base64 into the form of "%XX", and These "%" signs need to be converted when they are stored in the database, because the "%" sign has been used as a wildcard character in

ANSI SQL.

To solve this problem, an improved Base64 encoding for URLs can be used. It not only removes the padded '=' sign at the end, but also changes the " " and "/" in standard Base64 to "-" and "_" are eliminated, which eliminates the need for conversion during URL encoding, decoding and database storage, avoids the increase in the length of encoded information in the process, and unifies object identifiers in databases, forms, etc. format.

There is another improved Base64 variant for regular expressions, which changes " " and "/" to "!" and "-", because " ", "*" and the preceding ones are in IRCu The "[" and "]" used in regular expressions may have special meanings.

There are also some variants that change "/" to "_-" or "._" (used as an identifier name in programming languages) or ".-" (used in XML Nmtoken) or even "_:" (for Name in XML).

3. Other applications

1) Mozilla Thunderbird and Evolution use Base64 to keep email passwords secret

2) Base64 is also often used as a Simple "encryption" protects some data, while real encryption is often more cumbersome.

 3) Spammers use Base64 to evade anti-spam tools, because those tools usually do not translate Base64 messages.

 4) In LDIF files, Base64 is used as the encoded string.

The above is the detailed content of What is the use of base64 encoding?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn