Partilhar via


MSecurityLibrary library for symmetric encryption and hashing

This time I'm introducing one of the most favorite codes for me. I built this library a year ago while I was working with symmetric encryption. I felt that I need to do it myself instead of using any ready-made components because I either found a very complex component or a very simple one that doesn't satisfy my needs.

The library called MSecurityLibrary and it consists of only two classes

Encryption: does the symmetric encryption using Rijndael algorithm and a key size of 256 bits.

Hashing: hash any string with MD5 hashing algorithms

Encryption class has 11 public methods. I'll describe the main functions here.

public void encryptFile(string sourceFile,string distinationFile,string password)

public void encryptFile(string sourceFile,string distinationFile,byte[] key)

These two methods encrypt a file using either a password or an array of bytes as a key. You can use the generateKey() method to generate that key and save it in a file (usually should be put in a floppy disk to make it more secure).

public void decryptFile(string sourceFile,string distinationFile,string password)

public void decryptFile(string sourceFile,string distinationFile,byte[] key)

These two methods are the opposite of the others. They decrypt a file using either a password or a key.

public string encryptString(string inputString,string password)

public string encryptString(string inputString,byte[] key)

These two do the same but for strings. They take inputString parameter which will be encrypted using a password or a key

public string decryptString(string inputString,string password)

public string decryptString(string inputString,byte[] key)

The opposite to the previous two methods,

Hashing class has only one public method

public string HashStringWithMD5(string password)

This method takes a string and hashes it using MD5 algorithms and returns a string. This method is very powerful if you want to hash passwords in a database in case you want to save them secured.

I added a simple windows application that demonstrates all the functionality of the library along with the library here and the source code is available here

Have fun with encryption J

Mohamed