You are here

public static function Crypt::hashBase64 in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Component/Utility/Crypt.php \Drupal\Component\Utility\Crypt::hashBase64()
  2. 10 core/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.

48 calls to Crypt::hashBase64()
AggregatorTestRssController::testFeed in core/modules/aggregator/tests/modules/aggregator_test/src/Controller/AggregatorTestRssController.php
Generates a test feed and simulates last-modified and etags.
AnnotatedClassDiscovery::__construct in core/lib/Drupal/Component/Annotation/Plugin/Discovery/AnnotatedClassDiscovery.php
Constructs a new instance.
AssetDumper::dump in core/lib/Drupal/Core/Asset/AssetDumper.php
The file name for the CSS or JS cache file is generated from the hash of the aggregated contents of the files in $data. This forces proxies and browsers to download new CSS when the CSS changes.
AssetResolver::getCssAssets in core/lib/Drupal/Core/Asset/AssetResolver.php
Returns the CSS assets for the current response's libraries.
AssetResolver::getJsAssets in core/lib/Drupal/Core/Asset/AssetResolver.php
Returns the JavaScript assets for the current response's libraries.

... See full list

File

core/lib/Drupal/Component/Utility/Crypt.php, line 77

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);
}