This article mainly introduces common hash encryption functions in php, and analyzes in detail the usage of the hash Encryption Function in PHP in the form of examples. the code provides detailed annotations for ease of understanding, for more information about php hash Encryption functions, see the examples in this article. 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.