Author - StudySection Post Views - 822 views
Function

PHP – hash_hmac() Function

Definition and Usage

The hash_hmac() function generates keyed hash values using the HMAC algorithm.
HMAC is an abbreviation for keyed-hash message authentication code or hash-based message authentication code. It makes use of cryptographic hash functions like md5, sha-256, and a secret key to return the message digest hash of the given data.

Syntax

hash_hmac ( string $algo , string $data , string $key [, bool $raw_output = FALSE ] ) : string

Parameters

Parameter Description
algo Name of the hashing algorithm. Hash supports a wide range of algorithms, including md5, sha256, and others.
To see the complete list of available algorithms, look for hash_hmac_algos()
data The data you want to hash.
key The secret key to generate HMAC variant of the message digest.
raw_output The value is false by default, thus it returns lowercase hexits. It will return raw binary data if the value is true.

Return Values
The hash_hmac() method returns a string with a computed message digest in lowercase hexits. If raw_output is set to false, raw binary data will be returned.
PHP Version
This function will work with PHP versions greater than 5.1.2.
Example 1
Using hash_hmac() −
<?php
echo hash_hmac('md5', 'PHP - Hash hmac() Function', 'any_secretkey');
?>

Output

This will produce the following result −
65f76c2b226b566b03a467bbcfba6a58

Example 2
Using hash_hmac() with ripemd128 algorithm −
<?php
echo hash_hmac('ripemd128', 'PHP - Hash hmac() Function', 'any_secretkey');
?>

Output

This will produce the following result −
3955f952d6326196099da6f70bda9e2d

Example 3
To create hash_hmac with raw output set to true −
<?php
echo hash_hmac('ripemd128', 'PHP - Hash hmac() Function', 'any_secretkey', true);
?>

Output

This will produce the following result −
9U'R'2a' '''
ڞ-

People having good command over the French language can get a French certification from StudySection. StudySection offers both beginner level and expert level French Certification Exams to test the ability to communicate in the French language.

Leave a Reply

Your email address will not be published. Required fields are marked *

fiteesports.com rivierarw.com cratosroyalbet betwoon grandpashabet grandpashabet giriş deneme bonusu veren siteler casino siteleri