Private rgbKEY As Byte() = {12, 75, 31, 49, 55, 8, 250, 78, 66, 249, 1, 29, 2, 255, 124, 93, 6, 14, 75, 164, 75, 24, 73, 192}
Private rgbIV As Byte() = {89, 154, 106, 44, 67, 1, 164, 2, 78, 11, 83, 14, 245, 9, 22, 137, 130, 19, 197, 47, 75, 43, 111, 192}
Public Function TripleDESEncrypt(ByVal input As String) As String
If Not input Is Nothing Then
Dim objCryptoService As New TripleDESCryptoServiceProvider
Dim msCrypt As New MemoryStream
Dim csCrypt As New CryptoStream(msCrypt, objCryptoService.CreateEncryptor(rgbKEY, rgbIV), CryptoStreamMode.Write)
Dim swCrypt As New StreamWriter(csCrypt)
swCrypt.Write(input)
swCrypt.Flush()
msCrypt.Flush()
csCrypt.FlushFinalBlock()
Return Convert.ToBase64String(msCrypt.GetBuffer, 0, msCrypt.Length)
swCrypt.Close()
End If
End Function
Public Function TripleDESDecrypt(ByVal input As String) As String
If input <> Nothing Then
Dim cryptoProvider As New TripleDESCryptoServiceProvider
Dim buffer As Byte() = Convert.FromBase64String(input)
Dim ms As New MemoryStream(buffer)
Dim cs As New CryptoStream(ms, cryptoProvider.CreateDecryptor(rgbKEY, rgbIV), CryptoStreamMode.Read)
Dim sr As StreamReader = New StreamReader(cs)
Return sr.ReadToEnd()
End If
End Function
|