CryptoSys PKI examples VB6 to VB.NET

RNG_Initialize

Initializes the RNG from a seed file.

VB6/VBA

Debug.Print "Testing RNG_Initialize ..."
Dim strSeedFile As String
Dim nRet As Long
Dim abData() As Byte
Dim nDataLen As Long
Dim i As Integer

strSeedFile = "seed.dat"
' 1. Initialize
nRet = RNG_Initialize(strSeedFile, 0)
Debug.Print "RNG_Initialize('" & strSeedFile & "') returns " & nRet & " (expecting 0)"

' 2. Generate some random data
nDataLen = 24
ReDim abData(nDataLen - 1)
For i = 1 To 3
    Call RNG_Bytes(abData(0), nDataLen, "", 0)
    Debug.Print cnvHexStrFromBytes(abData)
Next

' 3. Update the seed file
nRet = RNG_UpdateSeedFile(strSeedFile, 0)
Debug.Print "RNG_UpdateSeedFile('" & strSeedFile & "') returns " & nRet & " (expecting 0)"

Output

Testing RNG_Initialize ...
RNG_Initialize('seed.dat') returns 0 (expecting 0)
D5C515735A8375ECC4DAA3B228459F2869905F4EE8A5B54D
845F5A2AD122D11E30C0FB609597EB11EB20C120AF1ED87D
70C4C1E6764618C00F33C10E7E61DB9C4F875EECA065A5D0
RNG_UpdateSeedFile('seed.dat') returns 0 (expecting 0)

VB.NET

Console.WriteLine("Testing RNG_Initialize ...")
Dim strSeedFile As String
Dim isOK As Boolean
Dim abData() As Byte
Dim nDataLen As Integer
Dim i As Integer

strSeedFile = "seed.dat"
' 1. Initialize
isOK = Rng.Initialize(strSeedFile)
Console.WriteLine("RNG_Initialize('" & strSeedFile & "') returns " & isOK & " (expecting True)")

' 2. Generate some random data
nDataLen = 24
For i = 1 To 3
    abData = Rng.Bytes(nDataLen)
    Console.WriteLine(Cnv.ToHex(abData))
Next

' 3. Update the seed file
isOK = Rng.UpdateSeedFile(strSeedFile)
Console.WriteLine("RNG_UpdateSeedFile('" & strSeedFile & "') returns " & isOK & " (expecting True)")

[Contents]

[HOME]   [NEXT: RNG_Number...]

Copyright © 2010-20 D.I. Management Services Pty Ltd. All rights reserved.