Since: 8.2

final class Secure implements CryptoSafeEngine (View source)

Generates cryptographically secure randomness using the operating system’s CSPRNG.

The randomness generated by this Random\Engine is suitable for all applications, including the generation of long-term secrets, such as encryption keys. The Random\Engine\Secure engine is the recommended safe default choice, unless the application requires either reproducible sequences or very high performance.

Methods

string
generate()

Generate cryptographically secure randomness

Details

string generate()

Generate cryptographically secure randomness

Returns cryptographically secure randomness.

Return Value

string

A non-empty string containing random bytes. The Random\Randomizer works with unsigned 64 bit integers internally. If the returned string contains more than 64 bit (8 byte) of randomness the exceeding bytes will be ignored. Other applications may be able to process more than 64 bit at once.

Exceptions

RandomException