Home  >  Article  >  Backend Development  >  How to use md5 function to encrypt strings under Linux using PHP script, linuxmd5_PHP tutorial

How to use md5 function to encrypt strings under Linux using PHP script, linuxmd5_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 09:48:17987browse

Use PHP script to encrypt strings with md5 function under Linux, linuxmd5

#touch  a.php  //创建a.php文件

#vi a.php  //用vi 编辑a.php文件

Enter a866c449ef872153e4115c2a5cd56813 and save

#php  a.php  //运行a.php文件

Display: e10adc3949ba59abbe56e057f20f883e


A. On Linux or Unix, md5sum is a tool program used to calculate and verify file message digests. Generally speaking, after installing Linux, there will be the tool md5sum, which can be run directly in the command line terminal. You can use the following command to get help on the md5sum command: man md5sum

#md5sum –help

There is a tip: "With no FILE, or when FILE is -, read standard input." The translation is "If there is no input file option or the file option is - , then read the input content from the standard brick", that is, you can Read strings directly from the keyboard to encrypt.

How to encrypt string using md5sum

# md5sum     //然后回车

123456      //输入123456.然后按两次ctrl+d.

Display:

Copy code The code is as follows: 123456e10adc3949ba59abbe56e057f20f883e The red color represents the encrypted value

You can also use the pipe command:

Copy code The code is as follows: #echo -n '123123' | md5sum

Or write an md5 encryption script, named md5.sh,

Copy the following content into the script:

Copy the code The code is as follows: #!/bin/bash

echo -n $1 | md5sum | awk '{print $1}'

After saving, give the script execution permission.

Copy the code The code is as follows: #sh md5.sh 123456

Display: e10adc3949ba59abbe56e057f20f883e

B. In fact, you can also put the text into a text file, and then use md5sum to encrypt and modify the text, and you can also get the string encrypted value. The process is as follows:

Copy code The code is as follows: #touch a.txt

#echo -n 123456 > a.txt //Write 123456 into the text file. Do not lose the –n parameter to avoid carriage return interference

#md5sum a.txt

Display: e10adc3949ba59abbe56e057f20f883e a.txt

ctrl d has two meanings:

The first is to send the end-of-file input character EOF to the program.

The second is to send an exit command to the program. After the program receives the signal, the specific action is to end the input and then wait, or to exit directly. It depends on how the program operates after catching the signal.
md5sum belongs to the first meaning. strl d is executed twice. The first time the EOF instruction is read, the next capture will be treated as an exit instruction. Programs such as shells will directly interpret ctrl d as an exit command.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1024134.htmlTechArticleUse PHP script to encrypt strings with md5 function under Linux, linuxmd5 #touch a.php //Create a.php file#vi a.php //Use vi to edit the a.php file and enter php echo md5(123456); into it...
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