Here is a VB example:
Imports System.Text
Imports System.Security.Cryptography
Public Class Cipher
Dim DefaultEncryptionKey As String
Dim des As New TripleDESCryptoServiceProvider()
Dim hashmd5 As New MD5CryptoServiceProvider()
Public Sub New()
DefaultEncryptionKey = "DefaulEncryptionKeyYouShouldProvideYourOwn"
End Sub
Public Function DeCipher(ByVal TextToDecipher As String) As String
Return DeCipher(TextToDecipher, DefaultEncryptionKey)
End Function
Public Function DeCipher(ByVal TextToDecipher As String, ByVal EncryptionKey As String) As String
Dim DeCipheredValue As String = Nothing
des.Key = hashmd5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(EncryptionKey))
des.Mode = CipherMode.ECB
Dim desdencrypt As ICryptoTransform = des.CreateDecryptor()
Dim buff() As Byte = Convert.FromBase64String(TextToDecipher)
DeCipheredValue = ASCIIEncoding.ASCII.GetString(desdencrypt.TransformFinalBlock(buff, 0, buff.Length))
Return DeCipheredValue
End Function
Public Function Cipher(ByVal TextToCipher As String) As String
Return Cipher(TextToCipher, DefaultEncryptionKey)
End Function
Public Function Cipher(ByVal TextToCipher As String, ByVal EncryptionKey As String) As String
Dim CipheredValue As String = Nothing
des.Key = hashmd5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(EncryptionKey))
des.Mode = CipherMode.ECB
Dim desdencrypt As ICryptoTransform = des.CreateEncryptor()
Dim MyASCIIEncoding = New ASCIIEncoding()
Dim buff() As Byte = ASCIIEncoding.ASCII.GetBytes(TextToCipher)
CipheredValue = Convert.ToBase64String(desdencrypt.TransformFinalBlock(buff, 0, buff.Length))
Return CipheredValue
End Function
End Class
Hector Correa