views:

88

answers:

4

I need to create a Microsoft Access database, but have a need, in one of my tables, for a single field to be strongly encrypted.

Since AES requires both a key and an initialization vector, I've decided to solve this problem by requiring a password to access the database (as the key), and a field in the table to hold a SHA1 hash of the plaintext of the encrypted field.

Does anyone know where I can find VBA-compatible code to actually do the encryption?

A: 

Read this over:

http://www.freevbcode.com/ShowCode.Asp?ID=2389

Mervyn
+1  A: 

Some alternatives to writing it from scratch;

  • You can do it with the native CryptoAPI (the root API is CryptAquireContext)
  • You can use Microsoft's CAPICOM which is a COM wrapper to the CryptoAPI and supports AES.
  • You can use a 3rd party library, the one from ebCrypt is excellent, compact and free.
Alex K.
A: 

You can do it with SlowAES, a Javascript implemnentation of AES, wrapped as a COM object.

more info in this other answer.
http://stackoverflow.com/questions/270510/how-to-encrypt-in-vbscript-using-aes/858525#858525

working source code here:
http://cheeso.members.winisp.net/srcview.aspx?dir=AES-example

Cheeso
A: 

The MS Knowledge Base provides VB code for using the CryptoAPI. Note that the example explains how to encrypt but not how to decrypt the results. But it's quite easy to do it, as the decrypt API declaration has almost the same arguments. Note, however, that the string-to-byte conversion routine in the example code will incorrectly strip trailing spaces during the decryption process, so you have to alter that code to fix that.

David-W-Fenton