CryptoSys PKI Pro Manual

RNG_Bytes

Generates a random set of byte data suitable for cryptographic keys.

VBA/VB6 Syntax

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

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

C/C++ Syntax

long __stdcall RNG_Bytes(unsigned char *lpOutput, long nOutBytes, const void *lpSeed, long nSeedLen);

Parameters

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

Returns (VBA/C)

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

VBA Wrapper Syntax

Public Function rngBytes (nBytes As Long) As Byte()

.NET Equivalent

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

C++ (STL) Equivalent

static bvec_t dipki::Rng::Bytes (int n)

Python Equivalent

static Rng.bytestring(n)

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. VB6/VBA users: for historical reasons, the seed parameter is passed as a String type and may contain any 8-bit value including the NUL (zero) value. The length of the seed must be specified (set nSeedLen as zero to ignore).

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 (VBA core function)

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)

Example (VBA wrapper function)

Dim i As Integer
For i = 1 To 10
    Debug.Print cnvHexStrFromBytes(rngBytes(32))
Next

See Also

RNG_BytesWithPrompt RNG_Number

[Contents] [Index]

[PREV: PWD_PromptEx...]   [Contents]   [Index]   
   [NEXT: RNG_BytesWithPrompt...]

Copyright © 2004-24 D.I. Management Services Pty Ltd. All rights reserved. Generated 2024-09-23T07:52:09Z.