function Crypt::randomBytesBase64

Same name in other branches
  1. 9 core/lib/Drupal/Component/Utility/Crypt.php \Drupal\Component\Utility\Crypt::randomBytesBase64()
  2. 8.9.x core/lib/Drupal/Component/Utility/Crypt.php \Drupal\Component\Utility\Crypt::randomBytesBase64()
  3. 11.x core/lib/Drupal/Component/Utility/Crypt.php \Drupal\Component\Utility\Crypt::randomBytesBase64()

Returns a URL-safe, base64 encoded string of highly randomized bytes.

Parameters

$count: The number of random bytes to fetch and base64 encode.

Return value

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

29 calls to Crypt::randomBytesBase64()
BigPipe::sendNoJsPlaceholders in core/modules/big_pipe/src/Render/BigPipe.php
Sends no-JS BigPipe placeholders' replacements as embedded HTML responses.
BigPipe::sendPreBody in core/modules/big_pipe/src/Render/BigPipe.php
Sends everything until just before </body>.
CsrfTokenGenerator::get in core/lib/Drupal/Core/Access/CsrfTokenGenerator.php
Generates a token based on $value, the user session, and the private key.
CsrfTokenGeneratorTest::setupDefaultExpectations in core/tests/Drupal/Tests/Core/Access/CsrfTokenGeneratorTest.php
Set up default expectations on the mocks.
CsrfTokenGeneratorTest::testGenerateSeedOnGet in core/tests/Drupal/Tests/Core/Access/CsrfTokenGeneratorTest.php
Tests that a new token seed is generated upon first use.

... See full list

File

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

Class

Crypt
Utility class for cryptographically-secure string handling routines.

Namespace

Drupal\Component\Utility

Code

public static function randomBytesBase64($count = 32) {
    return str_replace([
        '+',
        '/',
        '=',
    ], [
        '-',
        '_',
        '',
    ], base64_encode(random_bytes($count)));
}

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