File

Code

functiondrupal_hmac_base64($data, $key) {
// Casting $data and $key to strings here is necessary to avoid empty string
// results of the hash function if they are not scalar values. As this
// function is used in security-critical contexts like token validation it is
// important that it never returns an empty string.
$hmac = base64_encode(hash_hmac('sha256', (string)$data, (string)$key, TRUE));
// Modify the hmac so it's safe to use in URLs.
returnstrtr($hmac, array('+' => '-', '/' => '_', '=' => ''));
}