Share via

Using VBA 7 to create solution using CryptoAPI in Windows 7, 64-bit environment. Will this ever work?

Anonymous
2012-04-09T20:19:52+00:00

Hello,  I am trying to build a solution to encrypt/decrypt data using VBA 7 to make calls to CryptoAPI in a Windows 7, 64-bit environment.  I am trying to follow the code in the only two books that could help.  Cryptography forVisual Basics by Richard Bondi and Developing a Secure Application in Visual Basics.  This is very difficult process with numerous errors.  I am receiving errors on CrytoImportKey on the variable (m_lProvider) that hold the pointer to the handle of the provider.  Error:  ByRef type mismatch.  Declaring the variable with ByRef or ByVal produces the same error.

lResult = CryptImportKey(m_lProvider, abSessionKey(0), lSessionKeyLen, 0, CRYPT_EXPORTABLE, m_lHImportKey)

    If lResult = 0 Then

        'MsgBox ("Error " & CStr(Err.LastDllError) & " during CryptImportKey!")

        CheckGetLastError Err.LastDllError, Return_ErrNum, Return_ErrDesc, "CryptImportKey", False

        '-2146893817  - (80090007) Bad Version of provider.

    End If

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2012-04-10T04:28:20+00:00

When converting a 32-bit API to 64-bit API you need to make sure you change the right handlers and variables to be able to get it to work. Especially the DataTypes. More info on that you will find in below thread:

http://www.jkp-ads.com/articles/apideclarations.asp

A big help is to download the Office 2010 Help Files: Win32API_PtrSafe with 64-bit Support in here:

http://www.microsoft.com/download/en/confirmation.aspx?displaylang=en&id=9970

Also good thread for the code itself you can find here (note it's in VB):

http://www.rgagnon.com/examples/cryptoapi_in_vb.txt

Hope this helps,

Daniel

Was this answer helpful?

0 comments No comments

0 additional answers

Sort by: Most helpful