CryptoSys API Library Manual

RNG_NonceDataHex

Returns a specified-length random nonce (number used once) as a hexadecimal string. This is a safer version of the RNG_NonceHex function in version 2.

VB6/VBA Syntax

Public Declare Function RNG_NonceDataHex Lib "diCryptoSys.dll" (ByVal strOutput As String, ByVal nMaxChars As Long, ByVal nBytes As Long) As Long

nRet = RNG_NonceDataHex(strOutput, nMaxChars, nBytes)

Parameters

strOutput
[out] String array to be filled with random values expressed in hexadecimal.
nMaxChars
[in] Long specifying the maximum number of characters in strOutput.
nBytes
[in] Long specifying the number of required bytes in the nonce.

C/C++ Syntax

long _stdcall RNG_NonceDataHex(char *hexstr, long maxchars, long nbytes);

Returns (VB6/C)

Long: If successful, the return value is 0; otherwise it returns a non-zero error code.

.NET Equivalent

Rng.NonceHex Method

COM/ASP Equivalent

rng.NonceHex
Public Function KeyHex(ByVal nBytes As Long) As String

See rng.NonceHex.

Remarks

The array strOutput must be filled with dummy characters to two times nBytes before calling the function. The length of the output buffer in characters must be specified.

Example

This example will create a random number 20 bytes long in hexadecimal.

    Dim sHexData As String
    Dim nRet As Long
    Dim nBytes As Long

    nBytes = 20
    ' Set hex string length to 2 x # bytes required.
    sHexData = String(2 * nBytes, " ")
    nRet = RNG_NonceDataHex(sHexData, Len(sHexData), nBytes)
    Debug.Print sHexData

This useful wrapper function is in the Visual Basic declarations module.

Public Function rngNonceHex(nBytes As Long) As String
' Returns a random nonce nBytes long encoded in hex
    Dim strHex As String
    Dim nRet As Long
    
    strHex = String(nBytes * 2, " ")
    nRet = RNG_NonceDataHex(strHex, Len(strHex), nBytes)
    If nRet = 0 Then
        rngNonceHex = strHex
    End If
End Function

See Also

RNG_NonceData RNG_Number RNG_KeyBytes

[Contents] [Index]

[HOME]   [NEXT: RNG_Number...]

Copyright © 2001-11 D.I. Management Services Pty Ltd. All rights reserved.