Open In App

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.

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');
?>

Output:
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);                                
?>

Output:
65f3fc3c9085077f44ade6ce2d21eba4
eóüD­æÎ-!ë¤

Reference: http://php.net/manual/en/function.hash-hmac.php


Article Tags :