Here you go. This will encrypt the DES3 key in a 128 bit MD5Hash and then use that hash to encrypt at the 3x64 (192bit) DES3.
Imports System.Web.Security Imports System.Security.Cryptography Imports System.Text Imports Microsoft.Win32
Public Class Crypt Dim myKey As String Dim cryptDES3 As New TripleDESCryptoServiceProvider() Dim cryptMD5Hash As New MD5CryptoServiceProvider()
Public Sub New() myKey = "somekeyhere"
End Sub
Private Function Decrypt(ByVal myString As String) As String cryptDES3.Key = cryptMD5Hash.ComputeHash(ASCIIEncoding.ASCII.GetBytes(myKey)) cryptDES3.Mode = CipherMode.ECB Dim desdencrypt As ICryptoTransform = cryptDES3.CreateDecryptor() Dim buff() As Byte = Convert.FromBase64String(myString) Decrypt = ASCIIEncoding.ASCII.GetString(desdencrypt.TransformFinalBlock(buff, 0, buff.Length)) End Function
Private Function Encrypt(ByVal myString As String) As String cryptDES3.Key = cryptMD5Hash.ComputeHash(ASCIIEncoding.ASCII.GetBytes(myKey)) cryptDES3.Mode = CipherMode.ECB Dim desdencrypt As ICryptoTransform = cryptDES3.CreateEncryptor() Dim MyASCIIEncoding = New ASCIIEncoding() Dim buff() As Byte = ASCIIEncoding.ASCII.GetBytes(testo) Encrypt = Convert.ToBase64String(desdencrypt.TransformFinalBlock(buff, 0, buff.Length)) End Function
End ClassLabels: ASP.Net, Decrypt, Encrypt |