Encryption using CryptoAPI
This is the standard API you can use regardless of the underlying dll used to do the encryption. These dlls are called Cryptographic Service Providers (CSPs) and you get one as standard from Microsoft called "Microsoft Base Cryptographic Provider v1.0" This module uses the standard CSP, but this can be changed by changing the constant SERVICE_PROVIDER. There is additional code in this module to ensure that the encrypted values do not contain CR or LF characters so that the result can be written to a file.
The CSP connection and release are in seperate functions to the main encryption/decryption which must be called by the user at the start and end of all encryption.
A word of warning: If you are going to use WritePrivateProfileString to write the encrypted value to an ini file, you must write a vbNullString first to delete the existing entry as it does not clear previous entries when writing binary data. This is a problem if you are overwriting a value with a smaller one.
Instructions: Click the link below to download the code. Select 'Save' from the IE popup dialog. Once downloaded, open the .zip file from your local drive using WinZip or a comparable program to view the contents.