CryptoSys API Library Manual

RNG_KeyBytes

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

VBA/VB6 Syntax

Public Declare Function RNG_KeyBytes Lib "diCryptoSys.dll" (ByRef lpOutput As Byte, ByVal nBytes As Long, ByVal strSeed As String, ByVal nSeedLen As Long) As Long

nRet = RNG_KeyBytes(lpOutput(0), nBytes, strSeed, nSeedLen) ' Note the "(0)" after the byte array parameters

C/C++ Syntax

long __stdcall RNG_KeyBytes(unsigned char *lpOutput, long nOutputLen, const void *lpSeed, long nSeedLen);

Parameters

lpOutput
[out] array of sufficient length to receive the output.
nOutputLen
[in] value of the required key length in bytes.
lpSeed
[in] containing an (optional) user-specified seed to be used by the random number generator. Specify an empty string ("") or NULL to ignore..
nSeedLen
[in] specifiying the size of the seed in bytes.

Returns (VBA/C)

Always returns zero. If the function fails its continuous random number generator test, a critical error will occur. See Self Tests for more details.

VBA Wrapper Syntax

Public Function rngKeyBytes(nBytes As Long, Optional szSeed = "") As Byte()

.NET Equivalent

Rng.KeyBytes Method (Int32, Byte[])
Rng.KeyBytes Method (Int32, String)

Python Equivalent

static Rng.bytestring(n)

Remarks

The seed szSeed is optional and is added to the automatic seed values generated internally. The seed cannot directly affect the value of the output; it will just ensure that it will be different.

Example (VBA core function)

Dim abKey() As Byte
Dim nRet As Long
Dim nKeyBytes As Long
Dim i As Integer

nKeyBytes = 24
ReDim abKey(nKeyBytes - 1)
' Generate three successive 192-bit random keys with no seeding
For i = 1 To 3
	nRet = RNG_KeyBytes(abKey(0), nKeyBytes, "", 0)
	Debug.Print cnvHexStrFromBytes(abKey)
Next

Example (VBA wrapper function)

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

See Also

RNG_KeyHex

[Contents] [Index]

[PREV: RNG_Initialize...]   [Contents]   [Index]   
   [NEXT: RNG_KeyHex...]

Copyright © 2001-24 D.I. Management Services Pty Ltd. All rights reserved. Generated 2024-01-07T07:42:00Z.