Home > Backend Development > PHP Tutorial > Commonly used hash encryption functions in php, phphash encryption_PHP tutorial

Commonly used hash encryption functions in php, phphash encryption_PHP tutorial

WBOY
Release: 2016-07-13 10:13:22
Original
986 people have browsed it

php commonly used hash encryption function, phpash encryption

The examples in this article describe the commonly used hash encryption functions in PHP. Share it with everyone for your reference. The specific analysis is as follows:

Copy code The code is as follows:
$hash_list=hash_algos(); //Return the registered hash rule list

print_r($hash_list); //Display results

Create a file to calculate the hash value: file_put_contents('example.txt', 'the quick brown fox jumped over the lazy dog.');

Output hash value information:

Copy code The code is as follows:
echo hash_file('md5', 'example.txt');

$str="the quick brown fox jumped over the lazy dog."; //Define string
echo hash('ripemd160',$str); //Generate hash value

$ctx=hash_init('md5'); //Initialize a hash value
hash_update($ctx,'the quick brown fox'); //Pour data into the hash value
hash_update($ctx,'jumped over the lazy dog.'); //Pour data into the hash value
echo hash_final($ctx); //Output the final result

$str="the quick brown fox jumped over the lazy dog."; //Define string
$fp=tmpfile(); //Create a temporary file
fwrite($fp,$str); //Write string to temporary file
rewind($fp); //Rewind the position of the file pointer
$ctx=hash_init('md5'); //Initialize a hash value
hash_update_stream($ctx,$fp); //Pour data into the data stream
echo hash_final($ctx); //Output result


$str="the quick brown fox jumped over the lazy dog."; //Define string
echo hash_hmac('ripemd160',$str,'secret'); //Generate a hash value containing the key

/*Create a file and write the string into it*/
$file="example.txt"; //Define file name
$str=" the quick brown fox jumped over the lazy dog."; //Define string
file_put_contents($file,$str); //Write a string to the file
echo hash_hmac_file('md5',$file,'secret'); //Generate a hash value containing the key

$ctx=hash_init('sha1'); //Define string
hash_update($ctx,'the quick brown fox jumped over the lazy dog.'); //Pour data into the hash value
echo hash_final($ctx); //Output result

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/916060.htmlTechArticlephp commonly used hash encryption function, phphash encryption This article describes the commonly used hash encryption function in php. Share it with everyone for your reference. The specific analysis is as follows: Copy the code The code is as follows: $hash_l...
Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template