Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Text
- Imports System.Security.Cryptography
- Public Class Utils
- Public Class ConfigFile
- Public Property Port As Integer
- Public Property Username As String
- Public Property Password As String
- Public Sub SaveToFile(Path As String)
- Using File As New System.IO.FileStream(Path, System.IO.FileMode.Create)
- Dim Writer As New System.Xml.Serialization.XmlSerializer(GetType(ConfigFile))
- Writer.Serialize(File, Me)
- End Using
- End Sub
- Public Shared Function LoadFromFile(ByVal FilePath As String) As ConfigFile
- Using File As New System.IO.FileStream(FilePath, System.IO.FileMode.Open)
- Dim Reader As New System.Xml.Serialization.XmlSerializer(GetType(ConfigFile))
- Return DirectCast(Reader.Deserialize(File), ConfigFile)
- End Using
- End Function
- End Class
- Public Shared Function DecryptString(EncryptedString As String) As String
- If String.IsNullOrEmpty(EncryptedString) Then
- Return String.Empty
- Else
- Return Decrypt(EncryptedString, "N3st22", "88552299", 2, "464R5DFA5DL6LE28", 256)
- End If
- End Function
- Public Shared Function Decrypt(ByVal cipherText As String, _
- ByVal passPhrase As String, _
- ByVal saltValue As String, _
- ByVal passwordIterations As Integer, _
- ByVal initVector As String, _
- ByVal keySize As Integer) _
- As String
- Dim initVectorBytes As Byte()
- initVectorBytes = Encoding.ASCII.GetBytes(initVector)
- Dim saltValueBytes As Byte()
- saltValueBytes = Encoding.ASCII.GetBytes(saltValue)
- Dim cipherTextBytes As Byte()
- cipherTextBytes = System.Convert.FromBase64String(cipherText)
- Dim password As New Rfc2898DeriveBytes(passPhrase, _
- saltValueBytes, _
- passwordIterations)
- Dim keyBytes As Byte()
- keyBytes = password.GetBytes(CInt(keySize / 8))
- Dim symmetricKey As New AesCryptoServiceProvider
- symmetricKey.Mode = CipherMode.CBC
- Dim decryptor As ICryptoTransform
- decryptor = symmetricKey.CreateDecryptor(keyBytes, initVectorBytes)
- Dim memoryStream As System.IO.MemoryStream
- memoryStream = New System.IO.MemoryStream(cipherTextBytes)
- Dim cryptoStream As CryptoStream
- cryptoStream = New CryptoStream(memoryStream, _
- decryptor, _
- CryptoStreamMode.Read)
- Dim plainTextBytes As Byte()
- ReDim plainTextBytes(cipherTextBytes.Length)
- Dim decryptedByteCount As Integer
- decryptedByteCount = cryptoStream.Read(plainTextBytes, _
- 0, _
- plainTextBytes.Length)
- memoryStream.Close()
- cryptoStream.Close()
- Dim plainText As String
- plainText = Encoding.ASCII.GetString(plainTextBytes, _
- 0, _
- decryptedByteCount)
- System.Console.WriteLine(plainText)
- Return plainText
- End Function
- Public Class SsoIntegration
- Public Property Username As String
- Public Property Password As String
- End Class
- Sub Main()
- Dim test As New SsoIntegration With {.Username = "c.smith", .Password = Utils.DecryptString("fTEzAfYDoz1YzkqhQkH6GQFYKp1XY5hm7bjOP86yYxE=")}
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement