manoaratefy

AES Encryption

Mar 10th, 2017
190
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 AES_Encrypt(ByVal input As String, ByVal pass As String) As String
  2.         Dim AES As New System.Security.Cryptography.RijndaelManaged
  3.         Dim Hash_AES As New System.Security.Cryptography.MD5CryptoServiceProvider
  4.         Dim encrypted As String = ""
  5.         Try
  6.             Dim hash(31) As Byte
  7.             Dim temp As Byte() = Hash_AES.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(pass))
  8.             Array.Copy(temp, 0, hash, 0, 16)
  9.             Array.Copy(temp, 0, hash, 15, 16)
  10.             AES.Key = hash
  11.             AES.Mode = Security.Cryptography.CipherMode.ECB
  12.             Dim DESEncrypter As System.Security.Cryptography.ICryptoTransform = AES.CreateEncryptor
  13.             Dim Buffer As Byte() = System.Text.ASCIIEncoding.ASCII.GetBytes(input)
  14.             encrypted = Convert.ToBase64String(DESEncrypter.TransformFinalBlock(Buffer, 0, Buffer.Length))
  15.             Return encrypted
  16.         Catch ex As Exception
  17.             Return Nothing
  18.         End Try
  19.     End Function
  20.  
  21.     Public Function AES_Decrypt(ByVal input As String, ByVal pass As String) As String
  22.         Dim AES As New System.Security.Cryptography.RijndaelManaged
  23.         Dim Hash_AES As New System.Security.Cryptography.MD5CryptoServiceProvider
  24.         Dim decrypted As String = ""
  25.         Try
  26.             Dim hash(31) As Byte
  27.             Dim temp As Byte() = Hash_AES.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(pass))
  28.             Array.Copy(temp, 0, hash, 0, 16)
  29.             Array.Copy(temp, 0, hash, 15, 16)
  30.             AES.Key = hash
  31.             AES.Mode = Security.Cryptography.CipherMode.ECB
  32.             Dim DESDecrypter As System.Security.Cryptography.ICryptoTransform = AES.CreateDecryptor
  33.             Dim Buffer As Byte() = Convert.FromBase64String(input)
  34.             decrypted = System.Text.ASCIIEncoding.ASCII.GetString(DESDecrypter.TransformFinalBlock(Buffer, 0, Buffer.Length))
  35.             Return decrypted
  36.         Catch ex As Exception
  37.             Return Nothing
  38.         End Try
  39.     End Function
Advertisement
Add Comment
Please, Sign In to add comment