function drupal_hash_hmac_sha1 in Drupal 6
Calculates a hexadecimal encoded sha-1 hmac.
Parameters
string $data: String to be validated with the hmac.
string $key: A secret string key.
See RFC2104 (http://www.ietf.org/rfc/rfc2104.txt). Note, the result of this must be identical to using hash_hmac('sha1', $data, $key); We don't use that function since PHP can be missing it if it was compiled with the --disable-hash switch.
Return value
string A hexadecimal encoded sha-1 hmac.
1 call to drupal_hash_hmac_sha1()
- drupal_hmac_base64 in includes/
bootstrap.inc - Calculates a base-64 encoded, URL-safe sha-1 hmac.
File
- includes/
bootstrap.inc, line 1506 - Functions that need to be loaded on every Drupal request.
Code
function drupal_hash_hmac_sha1($data, $key) {
// Keys longer than the 64 byte block size must be hashed first.
if (strlen($key) > 64) {
$key = pack("H*", sha1($key));
}
return sha1((str_pad($key, 64, chr(0x0)) ^ str_repeat(chr(0x5c), 64)) . pack("H*", sha1((str_pad($key, 64, chr(0x0)) ^ str_repeat(chr(0x36), 64)) . $data)));
}