Advertisement
ZeekoSec

Tripple DES Encryption By Me.

Mar 26th, 2015
507
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.96 KB | None | 0 0
  1. Imports System.Collections.Generic
  2. Imports System.ComponentModel
  3. Imports System.Data
  4. Imports System.Drawing
  5. Imports System.Linq
  6. Imports System.Text
  7. Imports System.Windows.Forms
  8. Imports System.Security.Cryptography
  9. Imports System.IO
  10. Namespace Encryptionusing_Des
  11.     Public Partial Class Form1
  12.         Inherits Form
  13.         Public Sub New()
  14.             InitializeComponent()
  15.         End Sub
  16.         Private Sub Encrypt_Click(sender As Object, e As EventArgs)
  17.             Dim buffer As Byte() = Encryption(textBox1.Text, txtKey.Text)
  18.             Dim b As String = Convert.ToBase64String(buffer)
  19.             textBox2.Text = b
  20.         End Sub
  21.         Public Shared Function Encryption(PlainText As String, key As String) As Byte()
  22.             Dim des As TripleDES = CreateDES(key)
  23.             Dim ct As ICryptoTransform = des.CreateEncryptor()
  24.             Dim input As Byte() = Encoding.Unicode.GetBytes(PlainText)
  25.             Return ct.TransformFinalBlock(input, 0, input.Length)
  26.         End Function
  27.         Public Shared Function Decryption(CypherText As String, key As String) As String
  28.             Dim b As Byte() = Convert.FromBase64String(CypherText)
  29.             Dim des As TripleDES = CreateDES(key)
  30.             Dim ct As ICryptoTransform = des.CreateDecryptor()
  31.             Dim output As Byte() = ct.TransformFinalBlock(b, 0, b.Length)
  32.             Return Encoding.Unicode.GetString(output)
  33.         End Function
  34.         Private Sub Decrypt_Click(sender As Object, e As EventArgs)
  35.             textBox3.Text = Decryption(textBox2.Text, txtKey.Text)
  36.         End Sub
  37.         Private Shared Function CreateDES(key As String) As TripleDES
  38.             Dim md5 As MD5 = New MD5CryptoServiceProvider()
  39.             Dim des As TripleDES = New TripleDESCryptoServiceProvider()
  40.             des.Key = md5.ComputeHash(Encoding.Unicode.GetBytes(key))
  41.             des.IV = New Byte(des.BlockSize / 8 - 1) {}
  42.             Return des
  43.         End Function
  44.     End Class
  45. End Namespace
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement