How to use
1. Use hash_init() to obtain an incremental Hash operation handle and specify the encryption algorithm.
2. Use hash_update() to add strings, use hash_update_file() to add file content, and use hash_update_stream() to add stream content.
3. Use hash_final() to end the handle operation, perform Hash calculation and return the result value. The result value obtained is the result of hashing the string, file and stream contents together.
Example
// Increment HASH $fp = tmpfile(); fwrite($fp, 'Initialize a stream file'); rewind($fp); $h1 = hash_init('md5'); // Start incrementing Hash hash_update($h1, 'test increment'); // Ordinary string hash_update_file($h1, './create-phar.php'); // File hash_update_stream($h1, $fp); // Stream $v1 = hash_final($h1); // End Hash and return the result echo $v1, PHP_EOL; // 373df6cc50a1d7cd53608208e91be1e7 $h2 = hash_init('md5', HASH_HMAC, 'secret'); // Incremental HASH using HMAC algorithm hash_update($h2, 'test increment'); hash_update_file($h2, './create-phar.php'); hash_update_stream($h2, $fp); $v2 = hash_final($h2); echo $v2, PHP_EOL; // 34857ee5d8b573f6ee9ee20723470ea4
The above is the use of PHP incremental Hash function. I hope it will be helpful to everyone.