PHP | hash_hmac() Function
The hash_hmac() function is an inbuilt function in PHP which is used to generate the keyed hash value using the HMAC method.
Syntax:
string hash_hmac( $algo, $msg, $key, $raw_opt )
Parameters: This function accepts four parameters as mention above and describe below.
- $algo: It is the required parameter which is used to specify the selected hashing algorithm Ex. “md5”, “sha256”, “sha1”.
- $msg: This parameter is used to hold the message to be hashed.
- $key: This parameter is used to specify the shared secret key used for generating the HMAC variant of the message digest.
- $raw_opt: This parameter is used to hold the Boolean value. If it set to True then it returns raw binary data and if it set to False then it returns output lowercase hexits.
Return Value: This function returns a string containing the calculated message digest as lowercase hexits.
Below programs illustrate the hash_hmac() function in PHP:
Program 1:
<?php // PHP program to illustrate // the hash_hmac function echo hash_hmac('md5', 'GeeksforGeeks A Computer Science Portal', 'GFG_DATA'); ?> |
65f3fc3c9085077f44ade6ce2d21eba4
Program 2:
<?php // PHP program to illustrate // the hash_hmac function echo hash_hmac('md5', 'GeeksforGeeks A Computer Science Portal', 'GFG_DATA', false). "\n"; echo hash_hmac('md5', 'GeeksforGeeks A Computer Science Portal', 'GFG_DATA', true); ?> |
65f3fc3c9085077f44ade6ce2d21eba4 eóü<?DæÎ-!ë¤
Reference: http://php.net/manual/en/function.hash-hmac.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 ?
- D3.js | d3.set.has() Function
- D3.js | d3.map.set() Function
- PHP | max( ) Function
- p5.js | nf() Function
- p5.js | nfc() function
- PHP | Ds\Set contains() Function
- CSS | rgb() Function
- PHP | Ds\Set last() Function
- PHP | Ds\Set first() Function
- D3.js | d3.min() function
- p5.js | box() Function
- PHP | next() Function
- PHP | pos() 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.



