php Common hash Encryption Function
- 2021-08-05 09:24:34
- OfStack
In this paper, hash encryption functions commonly used in php are described by examples. Share it for your reference. The specific analysis is as follows:
$hash_list=hash_algos(); // Returns the registered hash Rule list
print_r($hash_list); // Display results
Create files to calculate hash values: file_put_contents ('example. txt', 'the ES14ES15ES16ES17ES18the ES20dog.');
Output hash value information:
echo hash_file('md5', 'example.txt');
$str="the quick brown fox jumped over the lazy dog."; // Definition string
echo hash('ripemd160',$str); // Generate a hash
$ctx=hash_init('md5'); // Initialization 1 A hash Value
hash_update($ctx,'the quick brown fox'); // Pouring data into a hash
hash_update($ctx,'jumped over the lazy dog.'); // Pouring data into a hash
echo hash_final($ctx); // Output the final result
$str="the quick brown fox jumped over the lazy dog."; // Definition string
$fp=tmpfile(); // Create 1 Temporary files
fwrite($fp,$str); // Write a string to a temporary file
rewind($fp); // Rewind the position of the file pointer
$ctx=hash_init('md5'); // Initialization 1 A hash Value
hash_update_stream($ctx,$fp); // Pouring data into the data stream
echo hash_final($ctx); // Output result
$str="the quick brown fox jumped over the lazy dog."; // Definition string
echo hash_hmac('ripemd160',$str,'secret'); // Object that contains the key hash Value
/* Create 1 Files and write strings to them */
$file="example.txt"; // Define file name
$str=" the quick brown fox jumped over the lazy dog."; // Definition string
file_put_contents($file,$str); // Write a string to a file
echo hash_hmac_file('md5',$file,'secret'); // Generate 1 Object containing the key hash Value
$ctx=hash_init('sha1'); // Definition string
hash_update($ctx,'the quick brown fox jumped over the lazy dog.'); // Pouring data into a hash
echo hash_final($ctx); // Output result
I hope this article is helpful to everyone's PHP programming.