You are here

function _piwik_hmac_base64 in Piwik Web Analytics 6.2

Backport of https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drup...

Calculates a base-64 encoded, URL-safe sha-256 hmac.

1 call to _piwik_hmac_base64()
piwik_footer in ./piwik.module
Implementation of hook_footer() to insert Javascript at the end of the page.

File

./piwik.module, line 525
Drupal Module: Piwik

Code

function _piwik_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.
  return strtr($hmac, array(
    '+' => '-',
    '/' => '_',
    '=' => '',
  ));
}