If you write a secure program, you should secure something such as a password, private key and something else…
For this propose, this article can help you to encrypt a string and decrypt a string by using some method.
This article explains 4 method to encrypt a string in .NET 2.0. There are 4 popular methods to encrypt a string:
- Triple DES
Note: For all of these methods, we have some required parameters:
- Specify a method
- Use a Private Key
What is a Private Key?
Private Key is a string with specific Length.
For DES method, the length of Private key string must be 8 characters.
For RC2 method, the length of Private key string must be Minimum 7 characters.
What is Initialization Vector?
The purpose of the Initialization vector is to prevent dictionary attacks. For example, without an initialization vector, "password" will always encrypt to the same thing, which makes a dictionary attack easier. If something unique for each entry (such as row ID) is used as an initialization vector, an attacker would have to apply a dictionary attack to each row individually, as opposed to the entire DB. ( Thanks for Wk633...)
Using the Code
For implementing encrypt a string, we have 2 classes:
Public class EncryptEngine
Public class Encryptor
Byte  IV;
Public string Encrypt(string SourceString)
When you set Method of Encryption and set Private Key, Press on Encrypt Button.
The program generates 2 parameters:
- Initialization Vector
- The Result ( encrypted string )
For decrypting a string, we need 2 parameters.
The program uses an Initialization Vector and result to decrypt a string.