How PHP uses the MD5 function to encrypt string instances under Linux

Source: Internet
Author: User
Tags md5 encryption
Using PHP scripts to encrypt strings using the MD5 function under Linux, simply install PHP on a Linux system and then manipulate the example in the command line to

#touch  a.php  //create a.php file #vi a.php  //edit a.php file with VI

<?php Echo MD5 (123456),?> input and save

#php  a.php  //Run a.php file

Display: e10adc3949ba59abbe56e057f20f883e

A. On Linux or UNIX, md5sum is the tool that is used to calculate and verify the file digest. In general, after installing Linux, there will be md5sum this tool, directly run directly at the command line terminal. You can use the following command to get the md5sum command to help man md5sum

#md5sum Help

There is a hint: "With no file, or when file was-, read standard input." "If the input file option is not available or the file option is--read the input from the tile", which can be encrypted by reading the string directly from the keyboard.

Ways to encrypt strings using md5sum

# md5sum     //Then enter 123456      //input 123456. Then press two times ctrl+d.

Show:

The code is as follows:

123456e10adc3949ba59abbe56e057f20f883e

Red indicates the value after encryption

You can also use the pipe command:

The code is as follows:

#echo-   n ' 123123 ' | md5sum

or write MD5 encryption script, called Md5.sh,

Copy the following into the script:

The code is as follows:

#!/bin/bashecho-   N $   | md5sum | awk ' {print '} '

After saving, execute permissions to the script.

The code is as follows:

#sh  md5.sh   123456

Display: e10adc3949ba59abbe56e057f20f883e

B. You can actually put the text in a text file, and then use md5sum encryption to change the text, you can also get the value of string encryption. The process is as follows:

The code is as follows:

#touch A.txt#echo-  n   123456 > A.txt    //write 123456 into a text file, do not lose the –n parameter, avoid the carriage return interference #md5sum    A.txt

Display: e10adc3949ba59abbe56e057f20f883e a.txt

There are two meanings of ctrl+d:

One is to send the file entry terminator to the program EOF.

The second is to send exit instructions to the program. The program receives the signal after the specific action is to end the input, and then wait, or direct exit, it depends on how the program captures the signal after the operation.
Md5sum belongs to the first meaning. Two plays Strl+d, the first time the EOF instruction is read, the capture will be treated as the exit instruction. A shell-type program will parse the CTRL+D directly into an exit instruction.

Related Article

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.