Search code examples
securityms-accessencryptionpgp

Easiest way to decrypt PGP-encrypted files from VBA (MS Access)


I need to write code that picks up PGP-encrypted files from an FTP location and processes them. The files will be encrypted with my public key (not that I have one yet). Obviously, I need a PGP library that I can use from within Microsoft Access. Can you recommend one that is easy to use?

I'm looking for something that doesn't require a huge amount of PKI knowledge. Ideally, something that will easily generate the one-off private/public key pair, and then have a simple routine for decryption.


Solution

  • A command line solution is good. If your database is an internal application, not to be redistributed, I can recommend Gnu Privacy Guard. This command-line based tool will allow you to do anything that you need to with regard to the OpenPGP standard.

    Within Access, you can use the Shell() command in a Macro like this:

    Public Sub DecryptFile(ByVal FileName As String)
      Dim strCommand As String
      strCommand = "C:\Program Files\GNU\GnuPG\gpg.exe " _
      & "--batch --passphrase ""My PassPhrase that I used""" & FileName
      Shell strCommand, vbNormalFocus
    End Sub
    

    This will run the command-line tool to decrypt the file. This syntax uses a plaintext version of your secret passphrase. This is not the most secure solution, but is acceptable if your database is internal and only used by trusted personnel. GnuPG supports other techniques to secure the passphrase.