Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- imports System.IO
- Imports System.Security.Cryptography
- Imports Microsoft.VisualBasic
- Namespace ITS
- Public Class OneLogin
- Public Function OneLogin_Decrypt(ByVal TokenKey As String, ByVal DataString As String) As String
- Dim ms As MemoryStream = Nothing
- Dim cs As CryptoStream = Nothing
- Try
- Using AES As New RijndaelManaged()
- AES.KeySize = 128
- AES.BlockSize = 128
- Dim EncryptedData As Byte() = System.Convert.FromBase64String(DataString)
- Dim SecretKey As New Rfc2898DeriveBytes(TokenKey, New Byte() {&H5E, &H7C, &H39, &H5E, &H54, &H4F, &H23, &H56, &H2A, &H47, &H48, &H63, &H54})
- Using Decryptor As ICryptoTransform = AES.CreateDecryptor(SecretKey.GetBytes(16), SecretKey.GetBytes(16))
- ms = New MemoryStream(EncryptedData)
- Using ms
- cs = New CryptoStream(ms, Decryptor, CryptoStreamMode.Read)
- Using cs
- Dim PlainText As Byte() = New Byte(EncryptedData.Length - 1) {}
- Return Encoding.Unicode.GetString(PlainText, 0, cs.Read(PlainText, 0, PlainText.Length))
- End Using
- End Using
- End Using
- End Using
- Catch ex As Exception
- Return "Error - " & ex.Message
- Finally
- If ms IsNot Nothing Then
- ms.Close()
- End If
- If cs IsNot Nothing Then
- cs.Close()
- End If
- End Try
- End Function
- End Class
- End Namespace
Add Comment
Please, Sign In to add comment