Generates a random set of byte data suitable for cryptographic keys.
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
long __stdcall RNG_KeyBytes(unsigned char *lpOutput, long nOutputLen, const void *lpSeed, long nSeedLen);
""
) or NULL to ignore..Always returns zero. If the function fails its continuous random number generator test, a critical error will occur. See Self Tests for more details.
Public Function rngKeyBytes
(nBytes As Long, Optional szSeed = "") As Byte()
Rng.KeyBytes Method (Int32, Byte[])
Rng.KeyBytes Method (Int32, String)
static Rng.bytestring(n)
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.
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
Dim i As Integer
For i = 1 To 10
Debug.Print cnvHexStrFromBytes(rngKeyBytes(32))
Next