Creating an Encryption Utility in C# [Part 3 of 3]
This is the Final Part of a Three-part series. Click here to read Part Two.
In part three of this three part series we are going to continue with our Encryption utility example and pick up where we left off. What we learned in the previous articles was how many various types of encryption algorithms there are and which one of those algorithms we will be using for our example.
We were able to create a new Windows application and begin adding our libraries and our IEncrypt interface. We will now continue with the GUI section of our example and create the remaining pieces of our application.
We will start to create a GUI front end that will allow you to type values into a text field and then encrypt and encode that value. This utility will also allow you to take values that are encrypted and encoded, then decode and decrypt them back to their original value. In the end we will have a fully functional utility that allows encryption and decryption and a working class that we can consume into any application web or windows.
This allows us to add another level of security to that web or Windows application. At that point the GUI front end could become your administration screen and allow you to have one central location to decrypt and encrypt values within all of your configuration files.
I just signed up at Server Intellect and couldn't be more pleased with my Windows Server! Check it out and see for yourself.
Continuing with our example
The next step in our example is to build the form that holds all of our buttons and textboxes used to encrypt and decrypt values. This form will consist of the following controls:
- Textbox called txtEncrypt
- Textbox called txtDecrypt [Read-Only]
- Listbox called lstbxList
- Button Called cmdEncrypt
- Button Called cmdEncode
- Button Called cmdDecode
- Button Called cmdDecrypt
- Button Called cmdReset
We will now explain what each one of these controls will do in our example and we will also bring you through the steps within the application so you can encrypt a value and then turn around and decrypt that value back to its original value.
The first control in our example is called the txtEncrypt control and it is a textbox. This is where we will type in our original plain text value that we want to be encrypted. There is no event for this control and no code behind. It is an editable field and is a required field for this example.
In this example we will be using the phrase “This is a Test” as our original string. Fig. 1
The next step is to select the “Encrypt” button. This will trigger an event that will take our original text and encrypt it. When the text is encrypted the value will look like. Fig. 2
Server Intellect offers Windows Hosting Dedicated Servers at affordable prices. I'm very pleased!
The next step is to select the “Encode” button. This will trigger an event that will take our encrypted value and encode that value into a Base64 encoded string that we can then use. Fig. 3
The next step is to select the “Decode” button. This will trigger an event that will take our encoded value and decode that value back into the encrypted value. Fig. 4:
The next step is to select the “Decrypt” button. This will trigger an event that will take our encrypted value and decrypt that value back into the original value. Fig. 5:
Try Server Intellect for Windows Server Hosting. Quality and Quantity!
While you are clicking on each one of the buttons we are keeping track of each step and storing it in the Listbox that we have on our screen. This acts like a logging mechanism so you will know the last process that affected the string value we are using. Fig. 6
The remaining button on our screen is the “Reset” button. This button simply clears all of the textboxes on the screen and also clears the Listbox as well so you can start a whole new series of encryption with a whole new string.
We have now taken our original value and have come full circle. We have encrypted the value, Encoded the value, Decoded the value and then finally Decrypted the value back to the original value.
Here is what the finished screen will look like. Fig. 7:
[Click to see full-size]
Server Intellect assists companies of all sizes with their hosting needs by offering fully configured server solutions coupled with proactive server management services. Server Intellect specializes in providing complete internet-ready server solutions backed by their expert 24/365 proactive support team.
We have now completed our Encryption example. Hopefully we have shown how easy it is to create an encryption utility that you can use in your applications. This example is for illustration purposes, and even though the application is fully functional we are by no means saying that you are ready to implement this scenario into a production environment without further research and making your own determination that this utility as a whole is a solution for you.
We kept things simple in this example so as not to confuse you with historical theories and the various applications and ways of how to do encryption. There are many ways to accomplish encryption and this example is just one of those ways, this example will however get you well on your way to a more secure environment.
What we have Learned
- What is Encryption
- How to use a Key during the Encryption
- How to use a Salt (IV) value during the Encryption
- How to create the Accessors we will be using
- How to create the methods we will be using
- How to bring it all together within a GUI front end