Home Backend Development PHP Tutorial Summary of usage of PHP encryption functions md5, crypt, base64_encode, etc.

Summary of usage of PHP encryption functions md5, crypt, base64_encode, etc.

Jul 08, 2017 am 10:27 AM
base64 crypt encode

php will use the encryption of the characters variable when registering, logging in or passing parameters in the URL. Let’s briefly introduce it: PHP’s own encryption function

Irreversible encryption functions are: md5(), crypt()
md5() is used to calculate MD5 hash. The syntax is: string md5(string str);
crypt() Encrypt string using UNIX’s standard encryption DES module. This is a one-way encryption function and cannot be decrypted. To compare strings, place the first two characters of the encrypted string in the salt parameter, and then compare the encrypted strings. The syntax is: string crypt(string str, string [salt]);
The reversible encryption is: base64_encode(), urlencode() and the corresponding decryption function: base64_decode(), urldecode()

base64_encode() MIME BASE64 encodes the string. This encoding method allows Chinese text or pictures to be transmitted smoothly over the Internet. The syntax is string base64_encode(string data); Its decryption function is: string base64_decode(string encoded_data); It will return to its original state
urlencode() URL-encodes the string. For example, spaces will become plus signs. The syntax is: string urlencode(string str);
Its decryption function is: string urldecode(string str); It will return to the original state

Look at the code:

Code As follows:

<?php 
define("str","墨剑"); 
echo &#39;md5 加密后的结果为:&#39;.md5(str).&#39;<br>&#39;;//md5 加密 
echo &#39;crypt加密后的结果为:&#39;.crypt(str,str).&#39;<br>&#39;;// crypt加密 
$base64encode=base64_encode(str);// base64_encode() 加密 
echo &#39;base64_encode加密后的结果为:&#39;.$base64encode.&#39;<br>&#39;; 
echo &#39;base64_decode解密后的结果为:&#39;.base64_decode($base64encode).&#39;<br>&#39;; //base64_decode()解密 
$urlencode=urlencode(str); //urlencode() 加密 
echo &#39;urlencode加密后的结果为:&#39;.$urlencode.&#39;<br>&#39;; 
echo &#39;urldecode解密后的结果为:&#39;.urldecode($urlencode).&#39;<br>&#39;;//urldecode() 解密 
?>
Copy after login

The output result is:
md5 The encrypted result is: ea796af15c74e90faeba49576fa7984b
crypt The encrypted result is: ink ylCzgTtYXPs
base64_encode The encrypted result is: xKu9ow==
base64_decode The result after decryption is: Mo Jian
The result after urlencode encryption is: %C4%AB%BD%A3
The result after urldecode decryption is: Mo Jian

The above is the detailed content of Summary of usage of PHP encryption functions md5, crypt, base64_encode, etc.. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to safely disable Windows Modules Installer Worker on Windows 11 How to safely disable Windows Modules Installer Worker on Windows 11 Apr 13, 2023 pm 03:43 PM

Whether you have an old computer or need your PC to run many tasks simultaneously, you may want to disable the Windows Modules Installer worker. The reason is that the Windows Modules Installer worker places a high load on your disk, CPU, and memory. You may use the best software to fix high CPU usage, but some reports show that it can even take up 100% CPU usage. While it can help you maintain a more secure and reliable system, it comes at a cost. Therefore, you can decide to keep it or disable it to avoid performance issues. In this article, we will explore in detail what is Windows Modules Installer Worker and how to enable or

How to implement linux base64 encryption and decryption How to implement linux base64 encryption and decryption May 14, 2023 am 11:58 AM

1. Base64 encode the file file and print it to the standard output [root@pps~]#base64filec25haWx3YXJyaW9yCg== You can also do this: [root@pps~]#catfile|base64c25haWx3YXJyaW9yCg== 2. Read the file content from the standard input, base64 encode and print to standard output [root@pps~]#base64snailwarriorc25haWx3YXJyaW9yCg==3. Encode the string "snailwarrior" and print to standard output [root@p

Top 10 cryptocurrency trading platforms, top ten recommended currency trading platform apps Top 10 cryptocurrency trading platforms, top ten recommended currency trading platform apps Mar 17, 2025 pm 06:03 PM

The top ten cryptocurrency trading platforms include: 1. OKX, 2. Binance, 3. Gate.io, 4. Kraken, 5. Huobi, 6. Coinbase, 7. KuCoin, 8. Crypto.com, 9. Bitfinex, 10. Gemini. Security, liquidity, handling fees, currency selection, user interface and customer support should be considered when choosing a platform.

How to implement base64 encoder in Java How to implement base64 encoder in Java Apr 28, 2023 pm 04:04 PM

Introduction What is Base64 encoding? Before answering this question, we need to understand the classification of files in computers. For computers, files can be divided into two categories, one is text files and the other is binary files. For binary files, their contents are represented in binary, which is not immediately understandable to humans. If you try to open a binary file with a text editor, you may see gibberish. This is because the encoding method of binary files is different from the encoding method of text files, so when the text editor tries to translate the binary files into text content, garbled characters will appear. For text files, there are many encoding methods, such as the earliest ASCII encoding and the currently commonly used UTF-8 and UTF

How to implement Base64 encoding and decoding in php How to implement Base64 encoding and decoding in php Mar 24, 2023 pm 05:11 PM

The Base64 algorithm is an encoding method that converts binary data into ASCII characters so that the data cannot be modified or damaged during transmission, and the true content of the data can also be hidden. In PHP, you can use built-in functions or manually write code to implement Base64 encoding and decoding.

Which of the top ten must-see websites in the currency circle? Which of the top ten must-see websites in the currency circle? Mar 04, 2025 pm 10:54 PM

In the ever-changing cryptocurrency space, a reliable source of information is crucial. To help investors and traders understand industry trends, this article lists the top ten must-see cryptocurrency websites. These sites provide in-depth market analysis, the latest industry news, technology updates and data-based insights to provide cryptocurrency enthusiasts with comprehensive resources to assist them in making informed investment decisions.

Top 10 easy-to-use and reliable digital currency trading software rankings recommended 2025 Top 10 easy-to-use and reliable digital currency trading software rankings recommended 2025 Feb 08, 2025 pm 08:15 PM

In an era of booming digital currencies, choosing a useful and reliable trading software is crucial. This article recommends the top 10 most trusted digital currency trading software in 2025, including Binance, Coinbase, FTX, Kraken, Huobi Global, KuCoin, Crypto.com, Phemex, Gemini and Gate.io. These platforms are evaluated based on factors such as user base, cryptocurrency selection, functionality, security, compliance and transaction fees, giving you the best choice to meet different needs.

How to use base64 command to encrypt linux command and execute it How to use base64 command to encrypt linux command and execute it May 17, 2023 pm 08:37 PM

1. Encrypt the command echo "ls-l" | 2. Decrypt the command and execute echobHMgLWwK | base64-d | At this time, you can only see the echo of the command, but not the command itself. What versions of Linux are there? Linux versions include: Deepin, UbuntuKylin, Manjaro, LinuxMint, Ubuntu and other versions. Among them, Deepin is one of the best-developed Linux distributions in China; Ubuntu Kylin is a derivative distribution based on Ubuntu; Manjaro is a Linux distribution based on Arch; LinuxMint's default Cinnamon desktop is similar to Win

See all articles