DataSafe, and app that encrypts files

Get the project zip file


screen shot of demo app

With gratitude and acknowledgement to all those who have posted code examples which I have used extensively over the years.


I created this project because I wanted to lock my password files and sensitive data. The program provides two cycles of encryption, allowing the user to provide a different pass-phrase for each cycle. The file interface is a ListView onto which the user can drag files or folders from an explorer.

As files are dropped into the list, a check is made to determine if the file has already been locked (encrypted). If locked, a lock icon is displayed before the file name.

To provide a simple Help interface, I wanted to write the instructions in a Word document, save as an Rich Text File (RTF), and then display the help RTF file in window.

This project provides examples of a Forms drag-and-drop interface, use of the .Net encryption library, and an example of loading an RTF document into a Forms RichTextBox.


Like nearly everything in .Net, drag-and-drop is extremely easy to do, if you know which one magic line of code is required (of the millions of lines in .Net). The ListView dragDrop interface is enabled by adding a dragDrop event handler and dragEnter event handler as shown. The majic lines of code are in the DragEnter event handler.

The key is adding a couple of lines of code in the dragEnter function which tells the windows to system to allow (or not allow)
a drop operation based on a test of the object type.

The next bit of work is accessing the list of dragged files in the drop event handler. Note, the files
are presented in the event args as an array of strings (full paths).


Encrpytion is a complex subject and so no attempt will be made to explain it. All encryption will fail when the passwords are compromised. So this program attempts to make passwords easier to remember by allowing for long phrases (any length), and requiring two seperate phrases for two seperate encryption cycles. The idea being that phrases such as “Today, president Obama announced” and “words which are similar to symile” randomly picked from text sources are just as random as “fh!g7#/98^%76” but are easier to remember.

The EcryptString class provide a simple encrypt/decrypt interface, where the string is actually a byte array whcih contains the full contents of the file.

The EncryptString class includes a more complex encryption class internally. This more complex class utilizes the .Net provided encryption libraries. I wrote this class originally about three years ago, and as memory serves, the core of the class was copied from the MSDN website.

The code is too long to post here, so just download the project (see link at the top of this page) and look at the Encryption.cs file.

RTF files in a RichTextBox

You would think dropping an RTF doc into a RichTextBox would be the most obvious thing in all of .Net. But it took me an hour – I do not use resource files enough to rember the various syntaxes and in this case we have to create a data stream from the resouce file, and map the stream to the RichTextBox.



Leave a Reply

Trackback this post  |  Subscribe to the comments via RSS Feed