Advertisement
ZeekoSec

DES-MD5 Encryption VB.NET

Mar 25th, 2015
537
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.30 KB | None | 0 0
  1. Imports System.IO
  2. Imports System.Text
  3. Imports System.Security.Cryptography
  4. Public Class Crypto
  5.     Private Shared DES As New TripleDESCryptoServiceProvider
  6.     Private Shared MD5 As New MD5CryptoServiceProvider
  7.     Public Shared Function MD5Hash(ByVal value As String) As Byte()
  8.         Return MD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(value))
  9.     End Function
  10.     Public Shared Function Encrypt(ByVal stringToEncrypt As String, ByVal key As String) As String
  11.         DES.Key = Crypto.MD5Hash(key)
  12.         DES.Mode = CipherMode.ECB
  13.         Dim Buffer As Byte() = ASCIIEncoding.ASCII.GetBytes(stringToEncrypt)
  14.         Return Convert.ToBase64String(DES.CreateEncryptor().TransformFinalBlock(Buffer, 0, Buffer.Length))
  15.     End Function
  16.     Public Shared Function Decrypt(ByVal encryptedString As String, ByVal key As String) As String
  17.         Try
  18.             DES.Key = Crypto.MD5Hash(key)
  19.             DES.Mode = CipherMode.ECB
  20.             Dim Buffer As Byte() = Convert.FromBase64String(encryptedString)
  21.             Return ASCIIEncoding.ASCII.GetString(DES.CreateDecryptor().TransformFinalBlock(Buffer, 0, Buffer.Length))
  22.         Catch ex As Exception
  23.             MessageBox.Show("Invalid, "Decryption Failed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  24.        End Try
  25.    End Function
  26. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement