function Crypt::hashBase64

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

49 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
AttributeDiscoveryWithAnnotations::getFileCacheSuffix in core/lib/Drupal/Core/Plugin/Discovery/AttributeDiscoveryWithAnnotations.php

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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.