Below is some encryption code I got from somewhere in the past. There is an
encryption function and a decryption function.
Key can be any string you want, e.g., Key = "19AKUpr7". You just have to
use the same key to decrypt as you did to encrypt.
There is one thing to watch for, though. When working with encrypting
querystrings in WebForms, I found that to avoid errors in the decryption
function you had to replace any spaces in the string to be decrypted with a
+ sign. I did not have this problem using the encryption and decryption
routines with Windows Forms.
Private Function EncryptTripleDES(ByVal Plaintext As String, ByVal Key As
String) As String
Dim DES As New
System.security.Cryptography.TripleDESCryptoServiceProvider
Dim hashMD5 As New
System.security.Cryptography.MD5CryptoServiceProvider
DES.Key =
hashMD5.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(Key))
DES.Mode = System.Security.Cryptography.CipherMode.ECB
Dim DESEncrypt As System.security.Cryptography.ICryptoTransform =
DES.CreateEncryptor()
Dim Buffer() As Byte =
System.Text.ASCIIEncoding.ASCII.GetBytes(Plaintext)
EncryptTripleDES = Convert.ToBase64String( _
DESEncrypt.TransformFinalBlock(Buffer, 0, Buffer.Length))
End Function
------
Private Function DecryptTripleDES(ByVal base64Text As String, ByVal Key As
String) As String
Dim DES As New
System.security.Cryptography.TripleDESCryptoServiceProvider
Dim hashMD5 As New
System.security.Cryptography.MD5CryptoServiceProvider
DES.Key =
hashMD5.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(Key))
DES.Mode = System.Security.Cryptography.CipherMode.ECB
Dim DESDecrypt As System.security.Cryptography.ICryptoTransform =
DES.CreateDecryptor()
Dim Buffer() As Byte = Convert.FromBase64String(base64Text)
DecryptTripleDES = System.Text.ASCIIEncoding.ASCII.GetString( _
DESDecrypt.TransformFinalBlock(Buffer, 0, Buffer.Length))
End Function