Results 1 to 9 of 9

Thread: API based random number generator for VB6

Hybrid View

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Oct 2008
    Posts
    1,238

    Re: API based random number generator for VB6

    Quote Originally Posted by Steve Grant View Post
    Ben you still need to modify the constant in the line CryptAcquireContext.
    Thanks for noticing that. The new code is now:
    Code:
    Private Declare Function CryptAcquireContext Lib "advapi32.dll" Alias "CryptAcquireContextA" (ByRef phProv As Long, ByVal pszContainer As String, ByVal pszProvider As String, ByVal dwProvType As Long, ByVal dwFlags As Long) As Long
    Private Declare Function CryptReleaseContext Lib "advapi32.dll" (ByVal hProv As Long, ByVal dwFlags As Long) As Long
    Private Declare Function CryptGenRandom Lib "advapi32.dll" (ByVal hProv As Long, ByVal dwLen As Long, ByRef pbBuffer As Any) As Long
    
    Private Const PROV_RSA_FULL As Long = 1
    Private Const CRYPT_VERIFYCONTEXT As Long = &HF0000000
    
    
    Public Sub GenRandom(ByVal ptrMemory As Long, ByVal lenMemory As Long)
        Dim hProv As Long
        CryptAcquireContext hProv, vbNullString, vbNullString, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT
        CryptGenRandom hProv, lenMemory, ByVal ptrMemory
        CryptReleaseContext hProv, 0
    End Function
    Last edited by Ben321; Jul 19th, 2016 at 07:26 PM. Reason: fixed error in GenRandom method definition

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width