File Protector

Note: Please Scroll Down to See the Download Link.

ABSTRACT:

This article is an expansion on a few of the articles here on Code Project. I noticed that there are a lot of articles and posts dealing with Cryptography in the .NET Framework. These were all well and good. They got me started. Then, as I was progressing and using the System. Security Cryptography namespace, I noticed that if the file was the right size and padded correctly, even using a bad password would output a file. This was not acceptable to me. So, I set out to write a class that would allow me to encrypt and then decrypt/verify that the contents had been written correctly.

These articles started me down the road of .NET Cryptography:

Using CryptoStream in C# by WillemM -- This was a short, simple, and to the point article. Good introduction to .NET crypto.

Simple encrypting and decrypting data in C# by DotNetThis -- Another good introduction, but does not do any file verification on the decrypted file.

Since none of these verified the output, I wrote a class to fix this.

What is interesting about this method and makes it different than the other articles' methods, is the fact that I write out the IV and Salt to the beginning of the output file. This adds a little more security to the file. For more information on these terms, check out Ritter's Crypto Glossary. Then after those two arrays are written, I encrypt and write the file size and a special tag (arbitrarily generated by me). These allow for some simple verifications of the file. After this, I do the encryption of the file, while hashing the data. Once the input file is completely encrypted, I encrypt the hash and write it out. By putting the hash at the end, I am able to verify the contents after decryption.

During decryption, I reverse the actions of encryption. First, I read both the IV and Salt from the file. I use these to create the SymmetricAlgorithm. Second, I decrypt and read the file size and the tag. This is the first step in verification--if the tag is equal to the const tag in the class, I know the file is so far not corrupted. Now comes the decryption of the file data. This took a little work, because normally I would just keep reading from the file until I could not read anymore. But I put the hash at the end. So, I had to figure out how to read only the amount of data in the file size

Project Introduction

The project aims at securing the important documents by collecting them into one project file with or without encrypting all files. During the project file creation. Files are added, password entry made to individual files and any/all files can be encrypted using Triple DES encryption mechanism and stored as single project file. The project may also be password protected. Anytime the archive can be viewed, edited i.e., file addition, removal is done.

Overview

Since none of these verified the output, I wrote a class to fix this.

What is interesting about this method and makes it different than the other articles' methods, is the fact that I write out the IV and Salt to the beginning of the output file. This adds a little more security to the file. For more information on these terms, check out Ritter's Crypto Glossary. Then after those two arrays are written, I encrypt and write the file size and a special tag (arbitrarily generated by me). These allow for some simple verifications of the file. After this, I do the encryption of the file, while hashing the data. Once the input file is completely encrypted, I encrypt the hash and write it out. By putting the hash at the end, I am able to verify the contents after decryption.

During decryption, I reverse the actions of encryption. First, I read both the IV and Salt from the file. I use these to create the SymmetricAlgorithm. Second, I decrypt and read the file size and the tag. This is the first step in verification--if the tag is equal to the const tag in the class, I know the file is so far not corrupted. Now comes the decryption of the file data. This took a little work, because normally I would just keep reading from the file until I could not read anymore. But I put the hash at the end. So, I had to figure out how to read only the amount of data in the file size

Existing System

This article is an expansion on a few of the articles here on Code Project. I noticed that there are a lot of articles and posts dealing with Cryptography in the .NET Framework. These were all well and good. They got me started. Then, as I was progressing and using the System. Security Cryptography namespace, I noticed that if the file was the right size and padded correctly, even using a bad password would output a file. This was not acceptable to me. So, I set out to write a class that would allow me to encrypt and then decrypt/verify that the contents had been written correctly.

Proposed System

This article is an expansion on a few of the articles here on Code Project. I noticed that there are a lot of articles and posts dealing with Cryptography in the .NET Framework. These were all well and good. They got me started. Then, as I was progressing and using the System. Security Cryptography namespace, I noticed that if the file was the right size and padded correctly, even using a bad password would output a file. This was not acceptable to me. So, I set out to write a class that would allow me to encrypt and then decrypt/verify that the contents had been written correctly.

These articles started me down the road of .NET Cryptography:

Using CryptoStream in C# by WillemM -- This was a short, simple, and to the point article. Good introduction to .NET crypto.

Simple encrypting and decrypting data in C# by DotNetThis -- Another good introduction, but does not do any file verification on the decrypted file.

Modules and its Description:

There are 2 modules in this project. They are:

.1. Enecryption

 2.Descryption

Enecryption:

encrypt and write the file size and a special tag (arbitrarily generated by me). These allow for some simple verifications of the file. After this, I do the encryption of the file, while hashing the data. Once the input file is completely encrypted, I encrypt the hash and write it out

Descryption:

During decryption, I reverse the actions of encryption. First, I read both the IV and Salt from the file. I use these to create the SymmetricAlgorithm. Second, I decrypt and read the file size and the tag. This is the first step in verification--if the tag is equal to the const tag in the class, I know the file is so far not corrupted. Now comes the decryption of the file data. This took a little work, because normally I would just keep reading from the file until I could not read anymore. But I put the hash at the end. So, I had to figure out how to read only the amount of data in the file size

Hardware Requirements

•         SYSTEM                    : Pentium IV 2.4 GHz

•         HARD DISK              : 40 GB

•         RAM                           : 512 MB

Software Requirements

•         Operating system     : Windows XP Professional

•         Technology               : Microsoft Visual Studio .Net 2008

•         Coding Language   : VB.Net

•         Back End                   : SQL Server 2005

 

Click here to download File Protector source code