VBTut
Home
Tutorials
Resources
'put this at the top of the code under public class form1 Dim DES As New System.Security.Cryptography.TripleDESCryptoServiceProvider Dim Hash As New System.Security.Cryptography.MD5CryptoServiceProvider 'encrypt Try DES.Key = Hash.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(TextBox1.Text)) DES.Mode = Security.Cryptography.CipherMode.ECB Dim DESEncrypter As System.Security.Cryptography.ICryptoTransform = DES.CreateEncryptor Dim Buffer As Byte() = System.Text.ASCIIEncoding.ASCII.GetBytes(TextBox2.Text) TextBox2.Text = Convert.ToBase64String(DESEncrypter.TransformFinalBlock(Buffer, 0, Buffer.Length)) Catch ex As Exception MessageBox.Show("The following error(s) have occurred: " & ex.Message, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error) End Try 'decrypt Try DES.Key = Hash.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(TextBox1.Text)) DES.Mode = Security.Cryptography.CipherMode.ECB Dim DESDecrypter As System.Security.Cryptography.ICryptoTransform = DES.CreateDecryptor Dim Buffer As Byte() = Convert.FromBase64String(TextBox2.Text) TextBox2.Text = System.Text.ASCIIEncoding.ASCII.GetString(DESDecrypter.TransformFinalBlock(Buffer, 0, Buffer.Length)) Catch ex As Exception MessageBox.Show("The following error(s) have occurred: " & ex.Message, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error) End Try