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