FastSitePHP\Security\Crypto\Random

Generates cryptographically secure pseudo-random bytes.

Código Fuente

GitHub

Código de Ejemplo

Generate a string of random bytes

// Generate cryptographically secure pseudo-random bytes that
// are suitable for cryptographic use and secure applications.
$bytes = \FastSitePHP\Security\Crypto\Random::bytes(32);

// Convert the bytes to another format:
$hex_bytes = bin2hex($bytes);
$base64_bytes = base64_encode($bytes);

// When using PHP 7 or newer you can simply call [random_bytes()]
$bytes = random_bytes(32);

Métodos

bytes($length)

Función Estática

This function calls [random_bytes()] for newer versions of PHP and if using any version of PHP 5 then the function is first polyfilled using compatibility functions from the [paragonie/random_compat] library. [paragonie/random_compat] is widely used and known to be secure. It is used in WordPress and many other projects.

Returns: string