CryptographicallySecurePseudoRandomNumberGenerator

The class that wraps the system's CSPRNG APIs, making it easy to retrieve cryptographically-secure pseudo-random bytes.

Constructors

this
this()

The constructor for a CSPRNG. When a CSPRNG is created with this constructor, the relevant libraries and functions from them are loaded. If they cannot be loaded, the constructor throws a CSPRNGException and the CSPRNG will not be created.

this
this()

The constructor for a CSPRNG. When a CSPRNG is created with this constructor, the pseudo-device, $(MONO /dev/random) is opened for reading (not writing). If it cannot be opened, the constructor throws a CSPRNGException and the CSPRNG will not be created.

Destructor

~this
~this()

Upon deleting the CSPRNG object, the libraries used are unloaded, and any relevant cryptographic constructs used by those libraries are released.

Members

Aliases

isUsingCNGAPI
alias isUsingCNGAPI = isUsingCryptographyNextGenerationApplicationProgrammingInterface
isUsingCNGApplicationProgrammingInterface
alias isUsingCNGApplicationProgrammingInterface = isUsingCryptographyNextGenerationApplicationProgrammingInterface
isUsingCryptoAPI
alias isUsingCryptoAPI = isUsingCryptoApplicationProgrammingInterface
isUsingCryptographyNextGenerationAPI
alias isUsingCryptographyNextGenerationAPI = isUsingCryptographyNextGenerationApplicationProgrammingInterface

Functions

getBytes
void[] getBytes(in size_t length)

Returns the specified number of cryptographically-secure pseudo-random bytes, using one of the system APIs.

getBytes
void[] getBytes(in size_t length)

Returns the specified number of cryptographically-secure pseudo-random bytes, using one of the system APIs.

getBytes
void[] getBytes(in size_t length)

Returns the specified number of cryptographically-secure pseudo-random bytes, using one of the system APIs.

Properties

isUsingCryptoApplicationProgrammingInterface
bool isUsingCryptoApplicationProgrammingInterface [@property getter]

Returns boolean indicating whether this library is using the Windows Crypto API to generate random bytes from the $(MONO CryptGenRandom) API function.

isUsingCryptographyNextGenerationApplicationProgrammingInterface
bool isUsingCryptographyNextGenerationApplicationProgrammingInterface [@property getter]

Returns boolean indicating whether this library is using the Windows Cryptography: Next Generation API to generate random bytes from the $(MONO BCryptGenRandom) API function.

isUsingRtlGenRandom
bool isUsingRtlGenRandom [@property getter]

Returns a boolean indicating whether this library was able to load $(MONO advapi32.dll) and $(MONO RtlGenRandom) from it, and will use $(MONO RtlGenRandom) to obtain secure random bytes.

Static variables

readBufferSize
size_t readBufferSize;

The size of the buffer used to read from $(MONO /dev/random)

Meta