ParagonIE_Sodium_Compat::randombytes_buf() – Generate a string of bytes from the kernel’s CSPRNG.

You appear to be a bot. Output may be restricted

Description

Generate a string of bytes from the kernel's CSPRNG.

Proudly uses /dev/urandom (if getrandom(2) is not available).

Usage

$string = ParagonIE_Sodium_Compat::randombytes_buf( $numBytes );

Parameters

$numBytes
( int ) required

Returns

string

Source

File name: wordpress/wp-includes/sodium_compat/src/Compat.php


Lines:

1 to 23 of 23
    public static function randombytes_buf($numBytes)
    {
        /* Type checks: */
        if (!is_int($numBytes)) {
            if (is_numeric($numBytes)) {
                $numBytes = (int) $numBytes;
            } else {
                throw new TypeError(
                    'Argument 1 must be an integer, ' . gettype($numBytes) . ' given.'
                );
            }
        }
        
/** @var positive-int $numBytes */
        if (self::use_fallback('randombytes_buf')) {
            return (string) call_user_func('\\Sodium\\randombytes_buf', $numBytes);
        }
        if ($numBytes < 0) {
            throw new SodiumException("Number of bytes must be a positive integer");
        }
        return random_bytes($numBytes);
    }
 

 View on GitHub View on Trac