public static function Crypt::hmacBase64

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

Parameters

string $data: String to be validated with the hmac.

string $key: A secret string key.

Return value

string A base-64 encoded sha-256 hmac, with + replaced with -, / with _ and any = padding characters removed.

6 calls to Crypt::hmacBase64()
drupal_generate_test_ua in drupal/core/includes/bootstrap.inc
Generates a user agent string with a HMAC and timestamp for simpletest.
drupal_get_token in drupal/core/includes/common.inc
Generates a token based on $value, the user session, and the private key.
image_style_path_token in drupal/core/modules/image/image.module
Generates a token to protect an image style derivative.
user_pass_rehash in drupal/core/modules/user/user.module
Creates a unique hash value for use in time-dependent per-user URLs.
WebTestBase::drupalGetToken in drupal/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
Generate a token for the currently logged in user.

... See full list

File

drupal/core/lib/Drupal/Component/Utility/Crypt.php, line 86
Contains \Drupal\Component\Utility\Crypt.

Class

Crypt
Utility class for cryptographically-secure string handling routines.

Namespace

Drupal\Component\Utility

Code

public static function hmacBase64($data, $key) {
  $hmac = base64_encode(hash_hmac('sha256', $data, $key, TRUE));

  // Modify the hmac so it's safe to use in URLs.
  return strtr($hmac, array(
    '+' => '-',
    '/' => '_',
    '=' => '',
  ));
}