Php common hash encryption function, phphash encryption _ PHP Tutorial

Source: Internet
Author: User
Php uses common hash encryption functions and phphash encryption. Php common hash encryption functions, phphphash encryption examples in this article describes common php hash Encryption functions. Share it with you for your reference. The specific analysis is as follows: Copy the code as follows: $ hash_l common hash encryption functions in php, and phphash encryption

This example 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 a string
Echo hash ('ripmd160 ', $ str); // Generate a hash value

$ Ctx = hash_init ('md5'); // initialize a hash value.
Hash_update ($ ctx, 'The quick brown Fox'); // injects data into the hash value
Hash_update ($ ctx, 'jumped over the lazy dog. '); // injects data into the hash value
Echo hash_final ($ ctx); // output the final result

$ Str = "the quick brown fox jumped over the lazy dog."; // define a string
$ Fp = tmpfile (); // create a temporary file
Fwrite ($ fp, $ str); // write a string to a temporary file
Rewind ($ fp); // The position of the inverted file pointer
$ Ctx = hash_init ('md5'); // initialize a hash value.
Hash_update_stream ($ ctx, $ fp); // injects data into the data stream
Echo hash_final ($ ctx); // output the result


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

/* Create a file and write the string to it */
$ File = "example.txt"; // defines the file name.
$ Str = "the quick brown fox jumped over the lazy dog."; // define a 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'); // defines the string
Hash_update ($ ctx, 'The quick brown fox jumped over the lazy dog. '); // injects data into the hash value
Echo hash_final ($ ctx); // output the result

I hope this article will help you with PHP programming.

Examples in this article describes common hash encryption functions in php. Share it with you for your reference. The code is as follows: $ hash_l...

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.