Advertisement
ZeekoSec

String Encrypt/Decrypt

Mar 27th, 2015
526
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.45 KB | None | 0 0
  1. Imports System
  2. Imports System.Security.Cryptography
  3. Imports System.Text
  4. Public Class Encryption
  5.    
  6.     Public Shared Function Encrypt(ByVal input As String, ByVal key As String) As String
  7.         Dim inputArray() As Byte = UTF8Encoding.UTF8.GetBytes(input)
  8.         Dim tripleDES As TripleDESCryptoServiceProvider = New TripleDESCryptoServiceProvider
  9.         tripleDES.Key = UTF8Encoding.UTF8.GetBytes(key)
  10.         tripleDES.Mode = CipherMode.ECB
  11.         tripleDES.Padding = PaddingMode.PKCS7
  12.         Dim cTransform As ICryptoTransform = tripleDES.CreateEncryptor
  13.         Dim resultArray() As Byte = cTransform.TransformFinalBlock(inputArray, 0, inputArray.Length)
  14.         tripleDES.Clear
  15.         Return Convert.ToBase64String(resultArray, 0, resultArray.Length)
  16.     End Function
  17.    
  18.     Public Shared Function Decrypt(ByVal input As String, ByVal key As String) As String
  19.         Dim inputArray() As Byte = Convert.FromBase64String(input)
  20.         Dim tripleDES As TripleDESCryptoServiceProvider = New TripleDESCryptoServiceProvider
  21.         tripleDES.Key = UTF8Encoding.UTF8.GetBytes(key)
  22.         tripleDES.Mode = CipherMode.ECB
  23.         tripleDES.Padding = PaddingMode.PKCS7
  24.         Dim cTransform As ICryptoTransform = tripleDES.CreateDecryptor
  25.         Dim resultArray() As Byte = cTransform.TransformFinalBlock(inputArray, 0, inputArray.Length)
  26.         tripleDES.Clear
  27.         Return UTF8Encoding.UTF8.GetString(resultArray)
  28.     End Function
  29. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement