Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.67 KB | None | 0 0
  1. Imports System.Text
  2. Imports System.Security.Cryptography
  3. Public Class Utils
  4. Public Class ConfigFile
  5. Public Property Port As Integer
  6. Public Property Username As String
  7. Public Property Password As String
  8.  
  9. Public Sub SaveToFile(Path As String)
  10. Using File As New System.IO.FileStream(Path, System.IO.FileMode.Create)
  11. Dim Writer As New System.Xml.Serialization.XmlSerializer(GetType(ConfigFile))
  12. Writer.Serialize(File, Me)
  13. End Using
  14. End Sub
  15.  
  16. Public Shared Function LoadFromFile(ByVal FilePath As String) As ConfigFile
  17. Using File As New System.IO.FileStream(FilePath, System.IO.FileMode.Open)
  18. Dim Reader As New System.Xml.Serialization.XmlSerializer(GetType(ConfigFile))
  19. Return DirectCast(Reader.Deserialize(File), ConfigFile)
  20. End Using
  21. End Function
  22.  
  23. End Class
  24. Public Shared Function DecryptString(EncryptedString As String) As String
  25. If String.IsNullOrEmpty(EncryptedString) Then
  26. Return String.Empty
  27. Else
  28. Return Decrypt(EncryptedString, "N3st22", "88552299", 2, "464R5DFA5DL6LE28", 256)
  29. End If
  30. End Function
  31.  
  32. Public Shared Function Decrypt(ByVal cipherText As String, _
  33. ByVal passPhrase As String, _
  34. ByVal saltValue As String, _
  35. ByVal passwordIterations As Integer, _
  36. ByVal initVector As String, _
  37. ByVal keySize As Integer) _
  38. As String
  39. Dim initVectorBytes As Byte()
  40. initVectorBytes = Encoding.ASCII.GetBytes(initVector)
  41. Dim saltValueBytes As Byte()
  42. saltValueBytes = Encoding.ASCII.GetBytes(saltValue)
  43. Dim cipherTextBytes As Byte()
  44. cipherTextBytes = System.Convert.FromBase64String(cipherText)
  45. Dim password As New Rfc2898DeriveBytes(passPhrase, _
  46. saltValueBytes, _
  47. passwordIterations)
  48. Dim keyBytes As Byte()
  49. keyBytes = password.GetBytes(CInt(keySize / 8))
  50. Dim symmetricKey As New AesCryptoServiceProvider
  51. symmetricKey.Mode = CipherMode.CBC
  52. Dim decryptor As ICryptoTransform
  53. decryptor = symmetricKey.CreateDecryptor(keyBytes, initVectorBytes)
  54. Dim memoryStream As System.IO.MemoryStream
  55. memoryStream = New System.IO.MemoryStream(cipherTextBytes)
  56. Dim cryptoStream As CryptoStream
  57. cryptoStream = New CryptoStream(memoryStream, _
  58. decryptor, _
  59. CryptoStreamMode.Read)
  60. Dim plainTextBytes As Byte()
  61. ReDim plainTextBytes(cipherTextBytes.Length)
  62. Dim decryptedByteCount As Integer
  63. decryptedByteCount = cryptoStream.Read(plainTextBytes, _
  64. 0, _
  65. plainTextBytes.Length)
  66. memoryStream.Close()
  67. cryptoStream.Close()
  68. Dim plainText As String
  69. plainText = Encoding.ASCII.GetString(plainTextBytes, _
  70. 0, _
  71. decryptedByteCount)
  72. System.Console.WriteLine(plainText)
  73. Return plainText
  74. End Function
  75.  
  76. Public Class SsoIntegration
  77. Public Property Username As String
  78. Public Property Password As String
  79. End Class
  80.  
  81. Sub Main()
  82. Dim test As New SsoIntegration With {.Username = "c.smith", .Password = Utils.DecryptString("fTEzAfYDoz1YzkqhQkH6GQFYKp1XY5hm7bjOP86yYxE=")}
  83. End Sub
  84. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement