User Tools

Site Tools


uphp:functions:hash_hmac

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

$key: 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

aes_decrypt() - Decrypt a string using the AES algorithm

aes_encrypt() - Encrypt a string using the AES algorithm

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