Common hash encryption functions in php

Source: Internet
Author: User
The code is as follows: $ hash_listhash_algos (); returns the registered hash rule list print_r ($ hash_list). the example of this article describes common hash encryption functions in php. Share it with you for your reference. The specific analysis is as follows:

The code is as follows:

$ Hash_list = hash_algos (); // return the registered hash rule list print_r ($ hash_list); // display the result


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:

The code is as follows:

Echo hash_file ('md5', 'example.txt '); $ str = "the quick brown fox jumped over the lazy dog. "; // define the string echo hash ('ripmd160 ', $ str); // Generate the hash value $ ctx = hash_init ('md5 '); // initialize a hash value hash_update ($ ctx, 'The quick brown Fox'); // injects hash_update ($ ctx, 'jumped over the lazy dog) into the hash value. '); // input the data echo hash_final ($ ctx) to the hash value; // output the final result $ str = "the quick brown fox jumped over the lazy dog. "; // define the string $ fp = tmpfile (); // create a temporary file fwrite ($ fp, $ str ); // write the string to the temporary file rewind ($ fp); // returns the position of the file pointer $ ctx = hash_init ('md5 '); // initialize a hash value hash_update_stream ($ ctx, $ fp); // input data to the data stream echo hash_final ($ ctx ); // output result $ str = "the quick brown fox jumped over the lazy dog. "; // define the string echo hash_hmac ('ripmd160 ', $ str, 'secret '); // Generate the hash value containing the key/* create a file and write the string into it */$ file = "example.txt "; // define the file name $ str = "the quick brown fox jumped over the lazy dog. "; // define the string file_put_contents ($ file, $ str); // write the echo hash_hmac_file ('md5', $ file, 'secret') to the file '); // Generate a hash value containing the key $ ctx = hash_init ('sha1'); // define the string hash_update ($ ctx, 'The quick brown fox jumped over the lazy dog. '); // input data to the hash value echo hash_final ($ ctx); // output the result

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.