Guest User

3DES Encryption Source

a guest
Apr 7th, 2011
2,119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 0.90 KB | None | 0 0
  1. Imports System.Text
  2. Imports System.Security.Cryptography
  3.  
  4. Public Class 3DES
  5.     Public Shared Function Encrypt(ByVal toEncrypt As String, ByVal key As String, ByVal useHashing As Boolean) As String
  6.   Dim keyArray As Byte()
  7.   Dim toEncryptArray As Byte() = UTF8Encoding.UTF8.GetBytes(toEncrypt)
  8.  
  9.   If useHashing Then
  10.     Dim hashmd5 As New MD5CryptoServiceProvider()
  11.     keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(key))
  12.   Else
  13.     keyArray = UTF8Encoding.UTF8.GetBytes(key)
  14.   End If
  15.  
  16.   Dim tdes As New TripleDESCryptoServiceProvider()
  17.   tdes.Key = keyArray
  18.   tdes.Mode = CipherMode.ECB
  19.   tdes.Padding = PaddingMode.PKCS7
  20.  
  21.   Dim cTransform As ICryptoTransform = tdes.CreateEncryptor()
  22.   Dim resultArray As Byte() = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length)
  23.  
  24.   Return Convert.ToBase64String(resultArray, 0, resultArray.Length)
  25.     End Function
  26. End Class
Advertisement
Add Comment
Please, Sign In to add comment