You are here

public static function Crypt::hashBase64 in Drupal 10

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

47 calls to Crypt::hashBase64()
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
AssetResolver::getJsAssets in core/lib/Drupal/Core/Asset/AssetResolver.php
BigPipeStrategy::generateBigPipePlaceholderId in core/modules/big_pipe/src/Render/Placeholder/BigPipeStrategy.php
Generates a BigPipe placeholder ID.

... See full list

File

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

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