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 is provided with detailed annotations for ease of understanding. For more information, see
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 is provided with detailed annotations for ease of understanding. For more information, see
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.
,