polish


 .::menu::.

Skip Navigation Links
main page
private
publications
C64 adventure
free projects
commercial projects
blog
spiritual

  
  .::guest book::.

Skip Navigation Links
guest book
sign in

.::site changes::.






© 2006-2008 Mariusz Zaleski
contact@aristo-samar.com






page visited 24937 times
last visit 28/08/2008 08:57:00



In this short publication I would like to introduce an Encrypter class written in C#.NET and providing a cipher encryption algorithm you may use to encrypt/decrypt files and memory blocks within your application.
At the bottom of this text you should find two fully functional, written as a console and windows applications providing a file encryption/decryption and using this same algorithm.


Lets try to use an Encrypter class in an example:



C# code:

 Encrypter encr = new Encrypter();
 encr.password = "password";
 encr.fileName = @"c:\file.txt";
 encr.buffer = 2; 

 try
 {
     encr.encryptFile();
 }
 catch (Exception ex)
 {
     MessageBox.Show(ex.Message);
 }



// create an Encrypter class object
// password key used within encryption process
// absolute file path
// capacity of an encryption buffer in Megabytes



// encryption method call



// exception message in exception catch block



As you have seen it is very easy to use Encryption class. Everything you have to do is to create an object, set few properties and call the parameterless encryptFile method providing encryption.

Here is few words about public properties you should set before calling encryptFile method.
The buffer property defines capacity of the memory buffer used to provide encryption process. Actually there is no need to set this property at all because it is set to 10MB automatically when you create an object of Encrypter class.

The password property defines the password-key used to encrypt a file. Password key should be between 6 and 2000 characters long.

In above example I have called encryptFile method within try/catch block. It is necessary if you want to catch any errors that may occur during encryption process. In case of any error there is no threat of loose any data. This has been achieved by Encrypter class by working with a file copies instead of original files.
An original file is replaced only when encryption process has succeeded. 


Right now lets have a look how to encrypt a memory block instead of a file residing on a HDD.



C# code:

 Encrypter encr = new Encrypter();
 encr.password = "password";

 try
 {
     enc.encryptMemory(ref byte[] array);
 }
 catch (Exception ex)
 {
     MessageBox.Show(ex.Message);
 }


// create an Encrypter class object
// password key used within encryption process



// encryption call with reference to the byte array



// exception message in exception catch block



As you can see to encrypt byte array you call an encryptMemory method passing a referrence to a byte array. This is actually only one difference between encrypting a byte array and a file apart from the fact that encrypting a byte array doesn't require neither a file path nor buffer size provided.

At this point you should have good understanding how to encrypt whether a file on your HDD or a byte array.
You now wonder how to decrypt already encrypted data. The solution is very easy. Just try to encrypt again this same data using this same password key. By doing this you will get your data back in original form.

The Encrypter class may be used to encrypt any file types like
archives, documents, executable files or even movies.

Please feel free to use my class withis any project (freeware/commercial) you have been working on.
If you have any queries please don't hesitate to contact me.


Kind regards
Mariusz 'Aristo/Samar' Zaleski




DOWNLOADABLE FILES:


  - Encrypter.cs - described above Encrypter class

  - encrypt.rar - fully functional console application written in C++ description

  - FileEncrypter.NET.rar - another fully functional application written in C#.NET description