Private Function Encrypt(pToEncrypt As String, sKey As String) As String
Dim dESCryptoServiceProvider As DESCryptoServiceProvider = New DESCryptoServiceProvider()
Dim bytes As Byte() = Encoding.[Default].GetBytes(pToEncrypt)
dESCryptoServiceProvider.Key = Encoding.ASCII.GetBytes(sKey)
dESCryptoServiceProvider.IV = Encoding.ASCII.GetBytes(sKey)
Dim memoryStream As MemoryStream = New MemoryStream()
Dim cryptoStream As CryptoStream = New CryptoStream(memoryStream, dESCryptoServiceProvider.CreateEncryptor(), CryptoStreamMode.Write)
cryptoStream.Write(bytes, 0, bytes.Length)
cryptoStream.FlushFinalBlock()
Dim stringBuilder As StringBuilder = New StringBuilder()
Dim array As Byte() = memoryStream.ToArray()
For i As Integer = 0 To array.Length - 1
Dim b As Byte = array(i)
stringBuilder.AppendFormat("{0:X2}", b)
Next
stringBuilder.ToString()
Return stringBuilder.ToString()
End Function
Private Function Decrypt(pToDecrypt As String, sKey As String) As String
Dim dESCryptoServiceProvider As DESCryptoServiceProvider = New DESCryptoServiceProvider()
Dim array As Byte() = New Byte(pToDecrypt.Length / 2 - 1) {}
For i As Integer = 0 To pToDecrypt.Length / 2 - 1
Dim num As Integer = Convert.ToInt32(pToDecrypt.Substring(i * 2, 2), 16)
array(i) = CByte(num)
Next
dESCryptoServiceProvider.Key = Encoding.ASCII.GetBytes(sKey)
dESCryptoServiceProvider.IV = Encoding.ASCII.GetBytes(sKey)
Dim memoryStream As MemoryStream = New MemoryStream()
Dim cryptoStream As CryptoStream = New CryptoStream(memoryStream, dESCryptoServiceProvider.CreateDecryptor(), CryptoStreamMode.Write)
cryptoStream.Write(array, 0, array.Length)
cryptoStream.FlushFinalBlock()
Dim stringBuilder As StringBuilder = New StringBuilder()
Return Encoding.[Default].GetString(memoryStream.ToArray())
End Function