You are here

public static function Crypt::hashBase64 in Service Container 7

Same name and namespace in other branches
  1. 7.2 lib/Drupal/Component/Utility/Crypt.php \Drupal\Component\Utility\Crypt::hashBase64()

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

Parameters

string $data: String to be hashed.

Return value

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

File

lib/Drupal/Component/Utility/Crypt.php, line 129
Contains \Drupal\Component\Utility\Crypt.

Class

Crypt
Utility class for cryptographically-secure string handling routines.

Namespace

Drupal\Component\Utility

Code

public static function hashBase64($data) {
  $hash = base64_encode(hash('sha256', $data, TRUE));

  // Modify the hash so it's safe to use in URLs.
  return str_replace([
    '+',
    '/',
    '=',
  ], [
    '-',
    '_',
    '',
  ], $hash);
}