Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Collections.Generic
- Imports System.ComponentModel
- Imports System.Data
- Imports System.Drawing
- Imports System.Linq
- Imports System.Text
- Imports System.Windows.Forms
- Imports System.Security.Cryptography
- Imports System.IO
- Namespace Encryptionusing_Des
- Public Partial Class Form1
- Inherits Form
- Public Sub New()
- InitializeComponent()
- End Sub
- Private Sub Encrypt_Click(sender As Object, e As EventArgs)
- Dim buffer As Byte() = Encryption(textBox1.Text, txtKey.Text)
- Dim b As String = Convert.ToBase64String(buffer)
- textBox2.Text = b
- End Sub
- Public Shared Function Encryption(PlainText As String, key As String) As Byte()
- Dim des As TripleDES = CreateDES(key)
- Dim ct As ICryptoTransform = des.CreateEncryptor()
- Dim input As Byte() = Encoding.Unicode.GetBytes(PlainText)
- Return ct.TransformFinalBlock(input, 0, input.Length)
- End Function
- Public Shared Function Decryption(CypherText As String, key As String) As String
- Dim b As Byte() = Convert.FromBase64String(CypherText)
- Dim des As TripleDES = CreateDES(key)
- Dim ct As ICryptoTransform = des.CreateDecryptor()
- Dim output As Byte() = ct.TransformFinalBlock(b, 0, b.Length)
- Return Encoding.Unicode.GetString(output)
- End Function
- Private Sub Decrypt_Click(sender As Object, e As EventArgs)
- textBox3.Text = Decryption(textBox2.Text, txtKey.Text)
- End Sub
- Private Shared Function CreateDES(key As String) As TripleDES
- Dim md5 As MD5 = New MD5CryptoServiceProvider()
- Dim des As TripleDES = New TripleDESCryptoServiceProvider()
- des.Key = md5.ComputeHash(Encoding.Unicode.GetBytes(key))
- des.IV = New Byte(des.BlockSize / 8 - 1) {}
- Return des
- End Function
- End Class
- End Namespace
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement