Triple DES Encryption and Decryption in WPF

Introduction

In this article we will see how a set of data can be encrypted and saved in file and again while reading it should be readable/decrypted based on key.

Crating WPF Application Project

Fire up Visual Studio 2008 and Create a WPF Application and name the project as CryptographyInWPF.

tripleDES1.gif

Here is the basic idea about this sample application. We will add User details and saved to the file, but it would be accessible based on key.

We need to use the following namespace:

tripleDES2.gif

Add the above to the Window1.xaml.cs.

First we will create a class that would help us storing User Data.

tripleDES3.gif

Now we will design the Window interface. Nothing much but we need a DataGrid and few Buttons and TextBoxes. The following figure will give you the design.

tripleDES4.gif

Before writing any other lines of code let me first intoduce you to the Encryption and Decryption methods as follows:

tripleDES5.gif

I have added an xml file which will be copied to the output Directory once build. The following is the setting for that.

tripleDES6.gif

The following method LoadData() will load the data from the xml file and populate into the DataGrid.

tripleDES7.gif

For Add operation we need to have the below methods and events that would help us achieving the Add Operation successfully.

tripleDES8.gif

tripleDES9.gif

It Seems we are done with the code, now we can test the application. Following are few screenshots when we add or read/load the data from xml file.

tripleDES10.gif

tripleDES11.gif

tripleDES12.gif

You won't feel the difference but if you open the file in the following path you would see that the xml content is encrypted.

tripleDES13.gif

tripleDES14.gif

Up Next
    Ebook Download
    View all
    Learn
    View all