PHP hash_hmac() Function: Generate Keyed Hash Values with HMAC
hash_hmac() is a built-in PHP function that generates keyed hash values using the HMAC method. HMAC (Keyed-Hashing for Message Authentication) is a type of message authentication code (MAC) that combines a cryptographic hash function and a secret cryptographic key.
The hash_hmac() function takes three parameters:
'algorithm': A string specifying the hash algorithm. Supported algorithms include 'md5', 'sha256', 'sha512', etc.'data': The string to be hashed.'key': The secret key used for HMAC calculation.
The function returns the computed HMAC as a string.
Here's an example of using hash_hmac():
$data = 'Hello, World!';
$key = 'secretkey';
$hash = hash_hmac('sha256', $data, $key);
echo $hash; // Output: 2e6e7bcb2c3d6c59b7a02e67d7f5fe3a3f5fe2f4e0e1f4b5e3f2e1d3c5b8a9c8
In this example, the HMAC-SHA256 hash is calculated for 'Hello, World!' using the secret key 'secretkey'. The resulting hash value is then printed.
原文地址: https://www.cveoy.top/t/topic/p78B 著作权归作者所有。请勿转载和采集!