· 8 years ago · Nov 24, 2017, 05:26 AM
1imports System.IO
2Imports System.Security.Cryptography
3Imports Microsoft.VisualBasic
4
5Namespace ITS
6 Public Class OneLogin
7
8Public Function OneLogin_Decrypt(ByVal TokenKey As String, ByVal DataString As String) As String
9 Dim ms As MemoryStream = Nothing
10 Dim cs As CryptoStream = Nothing
11 Try
12 Using AES As New RijndaelManaged()
13 AES.KeySize = 128
14 AES.BlockSize = 128
15 Dim EncryptedData As Byte() = System.Convert.FromBase64String(DataString)
16 Dim SecretKey As New Rfc2898DeriveBytes(TokenKey, New Byte() {&H5E, &H7C, &H39, &H5E, &H54, &H4F, &H23, &H56, &H2A, &H47, &H48, &H63, &H54})
17 Using Decryptor As ICryptoTransform = AES.CreateDecryptor(SecretKey.GetBytes(16), SecretKey.GetBytes(16))
18 ms = New MemoryStream(EncryptedData)
19 Using ms
20 cs = New CryptoStream(ms, Decryptor, CryptoStreamMode.Read)
21 Using cs
22 Dim PlainText As Byte() = New Byte(EncryptedData.Length - 1) {}
23 Return Encoding.Unicode.GetString(PlainText, 0, cs.Read(PlainText, 0, PlainText.Length))
24 End Using
25 End Using
26 End Using
27
28 End Using
29 Catch ex As Exception
30 Return "Error - " & ex.Message
31 Finally
32 If ms IsNot Nothing Then
33 ms.Close()
34 End If
35 If cs IsNot Nothing Then
36 cs.Close()
37 End If
38 End Try
39 End Function
40
41End Class
42End Namespace