How to encrypt strings using md5 functions in Linux using PHP scripts

Source: Internet
Author: User
This article mainly introduces how to use the md5 function to encrypt strings in Linux using PHP scripts. You only need to install PHP in Linux and then use the example in the command line, for more information, see

This article mainly introduces how to use the md5 function to encrypt strings in Linux using PHP scripts. You only need to install PHP in Linux and then use the example in the command line, for more information, see

# Touch a. php // create a. php file # vi a. php // use vi to edit the. php file

Set <? Php echo md5 (123456);?> Input and save

# Php a. php // run the. php file

Display: e10adc3949ba59abbe56e057f20f883e


A. in linux or Unix, md5sum is A tool program used to calculate and verify the file message digest. Generally, after Linux is installed, the md5sum tool runs directly on the command line terminal. You can use the following command to obtain the md5sum command to help man md5sum

# Md5sum-help

There is a prompt: "With no FILE, or when FILE is-, read standard input. "If the input file option is not available or the file option is-, the input content is read from the brick." This means that the string can be read directly from the keyboard for encryption.

How to encrypt a string using md5sum

# Md5sum // press ENTER 123456 // enter 123456. Press ctrl + d twice.

Display:

The Code is as follows:

123456e10adc3949ba59abbe56e057f20f883e

Red indicates the encrypted value.

You can also use the pipeline command:

The Code is as follows:

# Echo-n '000000' | md5sum

Or write an md5 encryption script named md5.sh,

Copy the following content to the script:

The Code is as follows:

#! /Bin/bash

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

Save and grant the script execution permission.

The Code is as follows:

# Sh md5.sh 123456

Display: e10adc3949ba59abbe56e057f20f883e

B. You can also put the text into a text file and use md5sum to encrypt and modify the text. You can also obtain the string-encrypted value. The process is as follows:

The Code is as follows:

# Touch a.txt

# Echo-n 123456> a.txt // write 123456 to a text file. The-n parameter cannot be lost to avoid interference with carriage return characters.

# Md5sum a.txt

Display: e10adc3949ba59abbe56e057f20f883e a.txt

Ctrl + d has two meanings:

The first is to send the object input Terminator EOF to the program.

Second, send the exit command to the program. After the program receives the signal, the specific action is to end the input, wait, or exit directly. It depends on how the program operates after capturing the signal.
Md5sum is the first meaning. Two strl + d times. The first time you read the EOF command, the second capture will be treated as the exit command. Shell programs directly parse ctrl + d as Exit commands.

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.