CryptoSys PKI Toolkit Manual

RNG_Bytes

RNG_Bytes generates a random set of byte data suitable for cryptographic keys.

VB6/VBA Syntax

Public Declare Function RNG_Bytes Lib "diCrPKI.dll" (ByRef abData As Byte, ByVal nDataLen As Long, ByVal strSeed As String, ByVal nSeedLen As Long) As Long

nRet = RNG_Bytes(abData(0), nDataLen, strSeed, nSeedLen)

Parameters

abData
[out] Byte array to receive the random data.
nDataLen
[in] Long specifying the required length in bytes.
strSeed
[in] String containing "user-supplied entropy" to be used by the random number generator. Specify an empty string ("") or NULL to ignore.
nSeedLen
[in] Long specifying the length of the seed string.

C/C++ Syntax

long _stdcall RNG_Bytes(unsigned char *lpOutput, long nOutputLen, const void *lpSeed, long nSeedLen);

Returns (VB6/C)

Long: If successful, the return value is zero. If the parameters are invalid, it returns a negative error code.

.NET Equivalent

Rng.Bytes Method (Int32)
Rng.Bytes Method (Int32, Byte)
Rng.Bytes Method (Int32, String)

Remarks

The maximum number of random bytes that can be requested in one call is 65,536 (64 kB). If you need more (!), make repeated calls. In the VB6 interface, for historical reasons, the seed ("user-supplied entropy") parameter is passed as a String type. This string is allowed contain NUL (zero) characters.

If the RNG fails its FIPS-140 continuous test, the DLL process will be terminated. There is no option to avoid this, but the chances of such a failure under normal conditions are absolutely miniscule - about 1 in 9 quintillion (billion billion billion). See Random Number Generator for more information on the RNG, entropy, and its compliance with the relevant standards.

Example

Dim abData() As Byte
Dim nDataLen As Long

nDataLen = 16
ReDim abData(nDataLen - 1)
Call RNG_Bytes(abData(0), nDataLen, "", 0)
Debug.Print cnvHexStrFromBytes(abData)

See Also

RNG_BytesWithPrompt RNG_Number

[Contents] [Index]

[HOME]   [NEXT: RNG_BytesWithPrompt...]

Copyright © 2004-10 D.I. Management Services Pty Ltd. All rights reserved.