VSM - January 2003 Getting Started column
Build a Cryptography Component
Stan Schultes - stan@vbnetexpert.com

The sample code for this column includes two directories. Encryption is a reusable cryptography services component. EncryptionTest is a test app for the Encryption component. To use Encryption in your own projects, you need to set a reference to Encryption.dll. 

To load the sample code on your machine, you must have the .NET Framework Release version or later installed. You don't need to have Visual Studio .NET installed to run the sample code, but the article assumes VS.NET for VB development. Unzip the two project zip files into the same directory. Unzip each into a subdirectory to create two directory trees: Encryption and EncryptionTest.

To open the combined project, open the Encryption.sln file in the Encryption directory. These projects are integrated into one solution file. Changes to the Encryption component are reflected in the EncryptionTest project the next time you run it.

While you're developing your file encryption routines, think about your file naming convention. If you overwrite your source file with the encrypted version (using the Replace File checkbox in the sample app), you can't recover the original unless you are able to properly decrypt the resulting file. If you write a new file, by adding an .enc file extension for example, you won't overwrite your original file until you're sure you encryption routines work.

In the EncryptionTest project \bin directory is a file named CryptoNotes.txt that you can use as a sample file to encrypt. This file contains extra info from the .NET Framework cryptography documentation. If you leave the Replace File checkbox cleared in the EncryptionTest app, a file named CryptoNotes.txt.enc is created on encryption. On decryption, a file named CryptoNotes_plain.txt is created. This protects the source file during development. If you check the Replace File checkbox, then the CryptoNotes.txt file is directly replaced by the encrypted version via a temp file.

NOTE: if you expect the encryption/decryption routines to be blazingly fast, then you'll be disappointed. These are processor intensive operations that take some time to execute on large files, expecially as you use larger key sizes.

WARNING: if you encrypt data and forget your passphrase, then your data is lost. There is no backdoor or crack you can use to get your data back (this isn't Microsoft Word). :)

