PHP | hash_hmac() Function Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article 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 Comment More infoAdvertise with us Next Article PHP | hash_hmac_algos() Function R R_Raj Follow Improve Article Tags : Web Technologies PHP PHP-function Similar Reads PHP | hash_hmac_file() Function The hash_hmac_file() function is an inbuilt function in PHP that is used to generate a keyed hash value using the contents of a given file. Syntax: string hash_hmac_file( $algo, $file, $key, $raw_opt ) Parameters: This function accepts four parameters as mentioned above and described below. $algo: 2 min read PHP | hash_hmac_algos() Function The hash_hmac_algos() function is an inbuilt function in PHP that is used to get the list of registered hashing algorithms suitable for the hash_hmac() function. Syntax: array hash_hmac_algos( void ) Parameters: This function does not accept any parameter. Return Value: This function returns an ar 2 min read PHP | hash_pbkdf2() Function The hash_pbkdf2() function is an inbuilt function in PHP which is used to generate a PBKDF2 key derivation of a supplied password. Syntax: string hash_pbkdf2( $algo, $pass, $salt, $itr, $len, $raw_opt ) Parameters: This function accept six parameters as mention above and describe below. $algo: It is 2 min read PHP | hash_file( ) Function The hash_file() function is an inbuilt function in PHP which is used to generate a hash value using the contents of a given file. Syntax: string hash_file( $algo, $file, $raw_opt ) Parameters: This function accept three parameters as mention above and describe below. $algo: It is the required parame 2 min read PHP | hash_copy() Function The hash_copy() function is an inbuilt function in PHP which is used to get the copy of hashing context. Syntax: hash_copy( $context ) Parameters: This function accepts single parameter $context which is used to specify the hashing context returned by hash_init() function. Return Value: This functio 1 min read PHP | hash_final() Function The hash_final() function is an inbuilt function in PHP which is used to finalize an incremental hash and return the resulting digest. Syntax: hash_final( $context, $raw_output ) Parameters: This function accept two parameters as mention above and describe below. $context: This parameter is used to 1 min read Like