Advertisement
ZeekoSec

String Encrypt/Decrypt

Mar 27th, 2015
506
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.01 KB | None | 0 0
  1. Public Function EncryptString(ByVal inputString As String) As String
  2.         Dim memStream As MemoryStream = Nothing
  3.         Try
  4.             Dim key() As Byte = New Byte(-1) {}
  5.             Dim IV() As Byte = New Byte() {12, 21, 43, 17, 57, 35, 67, 27}
  6.             Dim encryptKey As String = "aXb2uy4z"
  7.             key = Encoding.UTF8.GetBytes(encryptKey)
  8.             Dim byteInput() As Byte = Encoding.UTF8.GetBytes(inputString)
  9.             Dim provider As DESCryptoServiceProvider = New DESCryptoServiceProvider
  10.             memStream = New MemoryStream
  11.             Dim transform As ICryptoTransform = provider.CreateEncryptor(key, IV)
  12.             Dim cryptoStream As CryptoStream = New CryptoStream(memStream, transform, CryptoStreamMode.Write)
  13.             cryptoStream.Write(byteInput, 0, byteInput.Length)
  14.             cryptoStream.FlushFinalBlock
  15.         Catch ex As Exception
  16.             Response.Write(ex.Message)
  17.         End Try
  18.         Return Convert.ToBase64String(memStream.ToArray)
  19.     End Function
  20.  
  21. Public Function EncryptString(ByVal inputString As String) As String
  22.         Dim memStream As MemoryStream = Nothing
  23.         Try
  24.             Dim key() As Byte = New Byte(-1) {}
  25.             Dim IV() As Byte = New Byte() {12, 21, 43, 17, 57, 35, 67, 27}
  26.             Dim encryptKey As String = "aXb2uy4z"
  27.             key = Encoding.UTF8.GetBytes(encryptKey)
  28.             Dim byteInput() As Byte = Encoding.UTF8.GetBytes(inputString)
  29.             Dim provider As DESCryptoServiceProvider = New DESCryptoServiceProvider
  30.             memStream = New MemoryStream
  31.             Dim transform As ICryptoTransform = provider.CreateEncryptor(key, IV)
  32.             Dim cryptoStream As CryptoStream = New CryptoStream(memStream, transform, CryptoStreamMode.Write)
  33.             cryptoStream.Write(byteInput, 0, byteInput.Length)
  34.             cryptoStream.FlushFinalBlock
  35.         Catch ex As Exception
  36.             Response.Write(ex.Message)
  37.         End Try
  38.         Return Convert.ToBase64String(memStream.ToArray)
  39.     End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement