CryptoSys API Library Manual


Generates a random set of byte data suitable for cryptographic keys with a prompt for the user to enter random keystrokes and mouse movements.

VBA/VB6 Syntax

Public Declare Function RNG_BytesWithPrompt Lib "diCryptoSys.dll" (ByRef lpOutput As Byte, ByVal nOutputLen As Long, ByVal strPrompt As String, ByVal nOptions As Long) As Long

nRet = RNG_BytesWithPrompt(lpOutput(0), nOutputLen, strPrompt, nOptions) ' Note the "(0)" after the byte array parameters

C/C++ Syntax

long __stdcall RNG_BytesWithPrompt(unsigned char *lpOutput, long nOutputLen, const char *szPrompt, long nOptions);


[out] array to receive the random data.
[in] specifying the required length in bytes.
[in] specifying an (optional) prompt for the dialog. Specify an empty string ("") or NULL to use the default dialog.
[in] option flags:
API_DEFAULT (0) for default options
API_RNG_STRENGTH_112 to make user generate an estimated 112 bits of security (default)
API_RNG_STRENGTH_128 to make user generate an estimated 128 bits of security
API_RNG_STRENGTH_192 to make user generate an estimated 192 bits of security
API_RNG_STRENGTH_256 to make user generate an estimated 256 bits of security

Returns (VBA/C)

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

.NET Equivalent

Rng.BytesWithPrompt Method (Int32, Rng.Strength)
Rng.BytesWithPrompt Method (Int32, String, Rng.Strength)

Python Equivalent

static Rng.bytes_with_prompt(n, strength=Strength.BITS_112, prompt='')


Once started, there is no way to abandon the dialog that prompts the user except by terminating the process. Some applications may not handle the GUI dialog. Make your own tests to check. The maximum number of random bytes that can be requested in one call is 65,536 (64 kB). See Random Number Generator for more information on the RNG and its compliance with the relevant standards.


Dim abData() As Byte
Dim nDataLen As Long

' Allocate byte array for 16 bytes
nDataLen = 16
ReDim abData(nDataLen - 1)

' Default prompt with default 112-bit security strength
Call RNG_BytesWithPrompt(abData(0), nDataLen, "", 0)
Debug.Print cnvHexStrFromBytes(abData)

' User-selected prompt with 128-bit security strength
Call RNG_BytesWithPrompt(abData(0), nDataLen, "Our own prompt: type until done...", API_RNG_STRENGTH_128)
Debug.Print cnvHexStrFromBytes(abData)

See Also

RNG_KeyBytes RNG_HexWithPrompt

[Contents] [Index]

[PREV: PRF_Bytes...]   [Contents]   [Index]   
   [NEXT: RNG_HexWithPrompt...]

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