VBScript: Encrypt/Decrypt files

Windows provide a COM interface called Capicom that allow easy access to CryptAPI from a VBS; Microsoft SDK Capicom Package contains a sample script (cencrypt.vbs) that allow to cypher a text file (other useful scripts like hashing scripts are also available).

To encrypt a non-text file (e.g. an Access DB) you should encode from Base64-encoded format to plain text and then use cencrypt.vbs; a sample converter is available here http://www.fourmilab.ch/webtools/base64.

Let's see an example:
base64 /e database.mdb dbencoded.txt
cscript cencrypt.vbs encrypt -alg AES -lenght MAX dbencoded.txt dbencrypted.txt mypassphrase

To use these scripts, ensure that WSH (Windows Script Host) is installed and capicom.dll is regitered.

About author

Vittorio Pavesi