src/Drupal/Component/Utility/Crypt.php
public static function hmacBase64($data, $key) {
    // $data and $key being 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.
    if (!is_scalar($data) || !is_scalar($key)) {
      throw new \InvalidArgumentException('Both parameters passed to \Drupal\Component\Utility\Crypt::hmacBase64 must be scalar values.');
    }

    $hmac = base64_encode(hash_hmac('sha256', $data, $key, TRUE));
    // Modify the hmac so it's safe to use in URLs.
    return str_replace(['+', '/', '='], ['-', '_', ''], $hmac);
  }
public static function hmacBase64($data, $key) {
    // $data and $key being 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.
    if (!is_scalar($data) || !is_scalar($key)) {
      throw new \InvalidArgumentException('Both parameters passed to \Drupal\Component\Utility\Crypt::hmacBase64 must be scalar values.');
    }

    $hmac = base64_encode(hash_hmac('sha256', $data, $key, TRUE));
    // Modify the hmac so it's safe to use in URLs.
    return str_replace(['+', '/', '='], ['-', '_', ''], $hmac);
  }
public static function hmacBase64 ( $ data , $ key ) { // $data and $key being 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. if ( ! is_scalar ( $ data ) || ! is_scalar ( $ key ) ) { throw new \ InvalidArgumentException ( 'Both parameters passed to \Drupal\Component\Utility\Crypt::hmacBase64 must be scalar values.' ) ; } $ hmac = base64_encode ( hash_hmac ( 'sha256' , $ data , $ key , TRUE ) ) ; // Modify the hmac so it's safe to use in URLs. return str_replace ( [ '+' , '/' , '=' ] , [ '-' , '_' , '' ] , $ hmac ) ; }
Calculates a base-64 encoded, URL-safe sha-256 hmac.

@param mixed $data
Scalar value to be validated with the hmac.
@param mixed $key
A secret key, this can be any scalar value.

@return string
A base-64 encoded sha-256 hmac, with + replaced with -, / with _ and
any = padding characters removed.
Calculates a base - 64 encoded URL - safe sha - 256 hmac .