|
Simple Encryption/Decryption |
|
|
|
IntroductionThe world of encryption/decryption is filled with lots of details and terminology that makes it difficult to understand. Some folks believe the complexity of the subject is deliberate... to help keep the world of encryption programming secret. Like a lot of things in programming, there are quite a few choices for doing encryption and lots of ways to perform a simple encryption task... with no immediately obvious "right way". This fact is often blamed by users as the reason the subject of encryption is so difficult to understand. Well, the article is gonna be different... we will not bother with the list of different encryption types and the history of each algorithm. Instead, we are going to show you how to perform a common encryption/decryption task in the simplest possible way. String Encryption/Decryption ExampleSo, let's get started.... in this example, we will encrypt/decrypt a string using a common technique called Data Encryption Standard (DES) that requires a single password that is used for both encryption and decryption. That's an example of symmetrical encryption, but I promised not to go into too much detail... :) The password used by this encryption technique is stored in two 8-byte arrays. The password can be any combination of characters. The password doesn't have to contain printable ASCII characters... you can use any valid hex values (&H0 to &HFF) for the password. Note: In this case, the password is stored inside the program, so you won't have to remember it.
Next, let's look at the part of the program that takes an ordinary string and converts it into an encrypted string. This is done similar to an English to French "translator"... you push English into the translator, and you get French out.
Let's look at the steps evolved to encrypt a string in some additional detail...
Here is the second half of the example... to convert the encrypted text back into it's original text.
The steps are essentially the same as in the Encrypt function, except that this time we're using the CreateDecryptor() method. Yes, there are quite a few more techniques and encryption routines that can be used, and a ton stuff you can read about encryption... but I hope this simple example will help you down that road. Note: Storing passwords inside your application isn't totally secure. A reasonably resourceful hacker could "de-compile" your application and see the password. Documentation LinksDownloads/LinksDownload the VB.Net Source code examples used in this article:
Encryption.zip |