Guest User

Untitled

a guest
Nov 23rd, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. imports System.IO
  2. Imports System.Security.Cryptography
  3. Imports Microsoft.VisualBasic
  4.  
  5. Namespace ITS
  6. Public Class OneLogin
  7.  
  8. Public 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.  
  41. End Class
  42. End Namespace
Add Comment
Please, Sign In to add comment