PHP | hash_hmac_file() Function
The hash_hmac_file() function is an inbuilt function in PHP which is used generate a keyed hash value using contents of a given file.
Syntax:
string hash_hmac_file( $algo, $file, $key, $raw_opt )
Parameters: This function accept four parameters as mention above and describe below.
- $algo: It is the required parameter which specifies the selected hashing algorithm.
- $file: This parameter is used to specify the file url to be hashed.
- $key: This parameter is used to hold the shared secret key used for generating the HMAC.
- $raw_opt: If the parameter is set to true then output will be raw binary data and if the parameter is set to False then output will be lowercase hexits.
Return Value: This function returns a string containing the calculated message digest as lowercase hexits.
Below programs uses the file gfg.txt and contents of the file are:
GeeksforGeeks
A Computer Science Portal for Geeks
Below programs illustrate the hash_hmac_file() function in PHP:
Program 1:
<?php // PHP program to illustrate // hash_hmac_file function // Create a file to calculate hash of file_put_contents('gfg.txt', 'Geeks'); // Display result echo hash_hmac_file('sha1', 'gfg.txt', 'password', false); ?> |
Output:
a5365a345a41ac0780bf63e4d33576560b86163c
Program 2:
<?php // PHP program to illustrate // hash_hmac_file function // Create a file to calculate hash of file_put_contents('gfg.txt', 'Geeks'); // Display result echo hash_hmac_file('sha256', 'gfg.txt', 'password') . "</br>"; // Create a file to calculate hash of file_put_contents('gfg.txt', 'Content'); // Display result echo hash_hmac_file('md5', 'gfg.txt', 'password', false); ?> |
Output:
a73af6923445a30fbacd646622b254069f90c2502e63b1025918aa93f2ddca9d a7b2b24ac2334070c42a852fb5ef0c92
Reference: http://php.net/manual/en/function.hash-file.php
Recommended Posts:
- How to call a function that return another function in JavaScript ?
- How to get the function name from within that function using JavaScript ?
- PHP | min( ) Function
- PHP Ds\Map sum() Function
- p5.js | sin() function
- p5.js | tan() function
- D3.js | d3.map.set() Function
- D3.js | d3.hcl() Function
- p5.js | log() function
- p5.js | red() function
- PHP | max( ) Function
- p5.js | cos() function
- PHP | pos() Function
- p5.js | max() function
- PHP | key() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : GeekCode1



