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.

VBA/VB6 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)

C/C++ Syntax

long __stdcall RNG_NonceDataHex(char *szOutput, long nMaxChars, long nBytes);

Parameters

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

Returns (VBA/C)

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 NonceHex(ByVal nBytes As Long) As String

See rng.NonceHex.

C++ (STL) Equivalent

static std::string crsysapi::Rng::Hex (int n)

Remarks

The array szOutput 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]

[PREV: RNG_NonceData...]   [Contents]   [Index]   
   [NEXT: RNG_Number...]

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