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...