Imports System.Text
Imports System.Security.Cryptography
Public Class Form1
Private Const Chave As String = "TesteDeChave"
Private TripleDES As New TripleDESCryptoServiceProvider
Private MD5 As New MD5CryptoServiceProvider
Private Sub
Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Try
Dim byteArray() As Byte = ASCIIEncoding.ASCII.GetBytes(Chave)
TripleDES.Key = MD5.ComputeHash(byteArray)
TripleDES.Mode = CipherMode.ECB
Dim Buffer As Byte() = ASCIIEncoding.ASCII.GetBytes(TextBox1.Text)
TextBox2.Text = Convert.ToBase64String(TripleDES.CreateEncryptor().TransformFinalBlock(Buffer,
0, Buffer.Length))
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub
Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button2.Click
Try
Dim byteArray() As Byte = ASCIIEncoding.ASCII.GetBytes(Chave)
TripleDES.Key = MD5.ComputeHash(byteArray)
TripleDES.Mode = CipherMode.ECB
Dim Buffer As Byte() = Convert.FromBase64String(TextBox2.Text)
Label3.Text = "Texto Descriptografado:
" & ASCIIEncoding.ASCII.GetString(TripleDES.CreateDecryptor().TransformFinalBlock(Buffer,
0, Buffer.Length))
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
End Class
0 comentários:
Postar um comentário