RandomCryptoSafeEngine¶
Random\CryptoSafeEngine is a marker interface in PHP 8.2’s Random extension. Any Random\Engine that also implements this interface guarantees cryptographically secure output.
The only built-in engine implementing it is Random\Engine\Secure. Type-hinting against CryptoSafeEngine enforces that callers provide a secure source of randomness.
<?php
function generateToken(Random\CryptoSafeEngine $engine): string {
$randomizer = new Random\Randomizer($engine);
return bin2hex($randomizer->getBytes(16));
}
$token = generateToken(new Random\Engine\Secure());
?>
See also RandomCryptoSafeEngine and RandomEngineSecure.
Related : Random, Cryptography, Interface, , PHP Native Interfaces
Added in PHP 8.2