This article is built on top of 'XCrypt' -- the legendary cryptography wrapper which had been around in CodeProject for a while. Unfortunately the original author of the article has left the same unattended for several years. I brought the same to the attention of CP Team vide http://www.codeproject.com/Messages/4409016/Article-Adoption.aspx and as per the guidance I am submitting this alternative branch.
XCrypt helps as a generic encryption and decryption wrapper for .NET applications. Besides the same, it adds the following two algorithms (which are not part of .NET Base Class Library):
As of this writing, I did have an observation of another algorithm called 'Blakesharp' (http://www.codeproject.com/Articles/286937/BlakeSharp-A-Csharp-Implementation-of-the-BLAKE-Ha
). I have taken a humble initiative to get XCrypt update in having able to use this algorithm too.
- Basic Concepts, BlowFish, TwoFish: Credits to the parent XCrypt
- Blakesharp: http://www.codeproject.com/Articles/286937/BlakeSharp-A-Csharp-Implementation-of-the-BLAKE-Ha
Using the code
The sample code initializes the engine to 3DES, you also can call InitializeEngine again to reset the engine to a different algorithm.
<pre lang="cs" id="pre0" style="white-space: pre-wrap; word-wrap: break-word; margin-removed 0px; ">XCryptEngine xe = new XCryptEngine();
enc_str = xe.Encrypt(src_str);
dec_str = xe.Decrypt(enc_str);
Points of Interest
- XCrypt earns the credit of making me learn different encryption algorithms besides kindling interest to explore on the same.
- .NET has a good cryptography library but the paucity of documentation in MSDN as an end-to-end solution makes you run pillar to post whilst trying to decide on a particular algorithm. XCrypt endeavors to fulfill the gap.
The following are the changes from its parent (XCrypt):
- Included the two BlakeSharp algorithm into XCrypt as I had highlighted.
- The Test Application had hard-coded 'This is a test string' as the initial value'. To make it a bit more realistic I have replaced that with srcText.Text = Environment.UserName.Length > 0 ? Environment.UserName : "Hello World";
- The Test Application had bloated piece of code that the Algorithm Names were repeatedly hard-bound. I have tried replacing the same with a quick and small reflection code (LoadEnumMembers())
- The Test Application had a bug that for Hash where decryption would not be possible. Hence I have changed this by exposing two more public methods disabling Decrypt button for the same.
- I have removed the setup and other project which might not be of utility value for lot of users.
- First Update Built on XCrypt in a humble endeavor to make it a one-stop lookup for cryptography library in .NET
- Added a quick clipboard support to the application.