PHP | hash_hmac() Function Last Updated : 11 Jul, 2025 Comments Improve Suggest changes 2 Likes Like Report 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 // 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 // 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: https://www.php.net/manual/en/function.hash-hmac.php Create Quiz Comment R R_Raj Follow 2 Improve R R_Raj Follow 2 Improve Article Tags : Web Technologies PHP PHP-function Explore BasicsPHP Syntax4 min readPHP Variables5 min readPHP | Functions6 min readPHP Loops4 min readArrayPHP Arrays5 min readPHP Associative Arrays4 min readMultidimensional arrays in PHP5 min readSorting Arrays in PHP4 min readOOPs & InterfacesPHP Classes2 min readPHP | Constructors and Destructors5 min readPHP Access Modifiers4 min readMultiple Inheritance in PHP4 min readMySQL DatabasePHP | MySQL Database Introduction4 min readPHP Database connection2 min readPHP | MySQL ( Creating Database )3 min readPHP | MySQL ( Creating Table )3 min readPHP AdvancePHP Superglobals6 min readPHP | Regular Expressions12 min readPHP Form Handling4 min readPHP File Handling4 min readPHP | Uploading File3 min readPHP Cookies9 min readPHP | Sessions7 min read Like