Using PHP script to encrypt strings with MD5 functions under Linux _php instance

Source: Internet
Author: User
Tags md5 md5 encryption php script
#touch  a.php  //create a.php file

#vi a.php  //VI edit a.php file

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

#php  a.php  //Run a.php files

Show: e10adc3949ba59abbe56e057f20f883e


A. On Linux or UNIX, md5sum is the tool that is used to compute and validate the document digest. In general, the installation of Linux, there will be md5sum this tool, directly in the command line terminal to run directly. You can use the following command to get the md5sum command help man md5sum

#md5sum –help

There is a hint: "With no file," or "," The file is-, read standard input. " If you don't have the input file option or the file option is-, read the input from the tile, you can read the string directly from the keyboard to encrypt it.

Ways to encrypt strings using md5sum

# md5sum     //Then enter

123456      //input 123456. Then press two times ctrl+d.

Show:

Copy Code code as follows:
123456e10adc3949ba59abbe56e057f20f883e
Red represents the encrypted value

You can also use the pipe command:

Copy Code code as follows:
#echo-n ' 123123 ' | Md5sum

or write MD5 encryption script, named Md5.sh,

Copy the following content into the script:

Copy Code code as follows:
#!/bin/bash

Echo-n $ | md5sum | awk ' {print '} '

After saving, execute permissions to the script.

Copy Code code as follows:
#sh md5.sh 123456

Show: e10adc3949ba59abbe56e057f20f883e

B. In fact, you can also put text into 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:

Copy Code code as follows:
#touch A.txt

#echo-N 123456 > A.txt//write 123456 into text file, cannot lose –n parameter, avoid return interference

#md5sum A.txt

Show: e10adc3949ba59abbe56e057f20f883e a.txt

Ctrl+d has two meanings:

One is to send the file input end EOF to the program.

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 directly exit, it depends on the program to capture the signal after how the operation.
Md5sum belong to the first meaning. Two times strl+d, the first time to read the EOF instruction, again capture will be used as exit instructions. and the Shell class of programs, will directly resolve the ctrl+d to exit instructions.

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.