PHP Common hash encryption function _php technique

Source: Internet
Author: User
Tags md5 rewind

This article describes the PHP common hash encryption function. Share to everyone for your reference. The specific analysis is as follows:

Copy Code code as follows:
$hash _list=hash_algos (); Returns a list of registered hash rules

Print_r ($hash _list); Show results

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

Output hash Value information:

Copy Code code 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 '); Initializes a hash value
Hash_update ($ctx, ' The quick brown fox '); Pouring data into a hash value
Hash_update ($ctx, ' jumped over the lazy dog. '); Pouring data into a 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); Writes a string to a temporary file
Rewind ($FP); Rewind the location of the file pointer
$ctx =hash_init (' MD5 '); Initializes a hash value
Hash_update_stream ($ctx, $fp); Pouring data into the data stream
echo hash_final ($CTX); Output results


$str = "The quick brown fox jumped over the lazy dog." Define String
echo Hash_hmac (' ripemd160 ', $str, ' secret '); Generate a hash value that contains a key

/* Creates a file and writes the string to it * *
$file = "Example.txt"; Define file name
$str = "The quick brown fox jumped over the lazy dog." Define String
File_put_contents ($file, $STR); Writing a string to a file
echo hash_hmac_file (' MD5 ', $file, ' secret '); Generate a hash value that contains the key

$ctx =hash_init (' SHA1 '); Define String
Hash_update ($ctx, ' The quick brown fox jumped over the lazy dog. '); Pouring data into a hash value
echo hash_final ($CTX); Output results

I hope this article will help you with your PHP program design.

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.