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.
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)
long __stdcall RNG_NonceDataHex(char *szOutput, long nMaxChars, long nBytes);
If successful, the return value is 0; otherwise it returns a non-zero error code.
rng.NonceHex
Public Function NonceHex(ByVal nBytes As Long) As String
See rng.NonceHex
.
static std::string crsysapi::Rng::Hex (int n)
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.
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
RNG_NonceData
RNG_Number
RNG_KeyBytes