Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System
- Imports System.Security.Cryptography
- Imports System.Text
- Public Class Encryption
- Public Shared Function Encrypt(ByVal input As String, ByVal key As String) As String
- Dim inputArray() As Byte = UTF8Encoding.UTF8.GetBytes(input)
- Dim tripleDES As TripleDESCryptoServiceProvider = New TripleDESCryptoServiceProvider
- tripleDES.Key = UTF8Encoding.UTF8.GetBytes(key)
- tripleDES.Mode = CipherMode.ECB
- tripleDES.Padding = PaddingMode.PKCS7
- Dim cTransform As ICryptoTransform = tripleDES.CreateEncryptor
- Dim resultArray() As Byte = cTransform.TransformFinalBlock(inputArray, 0, inputArray.Length)
- tripleDES.Clear
- Return Convert.ToBase64String(resultArray, 0, resultArray.Length)
- End Function
- Public Shared Function Decrypt(ByVal input As String, ByVal key As String) As String
- Dim inputArray() As Byte = Convert.FromBase64String(input)
- Dim tripleDES As TripleDESCryptoServiceProvider = New TripleDESCryptoServiceProvider
- tripleDES.Key = UTF8Encoding.UTF8.GetBytes(key)
- tripleDES.Mode = CipherMode.ECB
- tripleDES.Padding = PaddingMode.PKCS7
- Dim cTransform As ICryptoTransform = tripleDES.CreateDecryptor
- Dim resultArray() As Byte = cTransform.TransformFinalBlock(inputArray, 0, inputArray.Length)
- tripleDES.Clear
- Return UTF8Encoding.UTF8.GetString(resultArray)
- End Function
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement