User Tools

Site Tools


uphp:functions:hash_hmac

This is an old revision of the document!


hash_hmac

WMMEGA FW >= 2.1030 WM2 FW >= 3.1130

Generate a keyed hash value using the HMAC method

Description

string hash_hmac ( string $algorithm , string $data , string $key )

This can be used for cryptography or just for checksum calculations.

Parameter

$algorithm: Name of selected hashing algorithm. Current algorithms supported are:

Parameter Algorithm Return Size (characters)
md5 MD5 32
sha1 SHA-1 40
sha224 SHA-224 56
sha256 SHA-256 64
sha384 SHA-384 96
sha512 SHA-512 128

$data: String of characters to calculate hash for

$keyspan style="color:black">: String of characters of key to be used in hash calculation

Return Values

String: Hash result (as hexadecimal number) of data. See above for expected length

Example

<?
 
// Get the parameters from the URL
 
$algo=$_GET['algorithm'];
$key=$_GET['key'];;
$data=$_GET['data'];
 
 
// make sure parameters are passed properly
if (!$algo) {
    print("You need to specify an algorithm");
    die();
}
if (!$key) {
    print("You need to specify a key");
    die();
}
if (!$data) {
    print("You need to specify a data parameter");
    die();
}
 
// calculate the hash
$res = hash_hmac($algo,$data,$key);
 
// output the rsults
print($algo." hash for key ".$key." and data ".$data." = ".$res);
 
?>

See Also

md5() - Calculate the MD5 hash of a string

sha1() - Calculate the SHA-1 hash of a string

md5_file() - Calculate the MD5 hash of a file

uphp/functions/hash_hmac.1555386840.txt.gz · Last modified: 2021/09/13 05:56 (external edit)