Help with VBA encryption/decryption, library reference, etc... RRS feed

  • Question

  • I would like to encrypt a file with password + salt in VBA. and would like some help implementing CryptEncryptMessage ( and CryptDecryptMessage (

    I have been able to do this in C#.NET, but my requirements are to do this ONLY in VBA.

    so far this is what i have (along with massive brain farts):

    Option Explicit
    Option Base 0
    Option Compare Binary
    Declare Sub CryptEncryptMessage Lib "C:\Windows\System32\crypt32.dll" ()
    Public Sub test()
        Dim uPath As String
        Dim ePath As String
        Dim pSalt As String
        Dim pWord As String
        pSalt = "someThingInteresting"
        pWord = "someThingLessInteresting"
        uPath = "C:\TestFile.xml"
        ePath = "C:\Encrypted.xml"
        ' Do Stuff...
        ' CryptEncryptMessage...
    End Sub

    Tuesday, March 31, 2015 9:34 PM

All replies

  • I created a .NET DLL that i add to the references then call in the VBA code.

    I'll post the code if any one asks.

    • Edited by Rogge Monday, April 27, 2015 7:00 PM
    Monday, April 27, 2015 6:59 PM
  • I could not get VBA to make a reference to crypt32.dll.  It was able to make a reference to cryptext.dll.    I often call C# .Net from VBA.
    Tuesday, April 28, 2015 1:21 PM