Reputation: 7532
I have an encrypted string that is read out of a file. My issue is that it is not coming into a variable like it shows in the file so the resulting decryption is wrong.
Here is the string in the file: û«hoágè~Àê´•§™Ý
This code Works:
Dim oldpass As String = "û«hoágè~Àê´•§™Ý"
MsgBox(mylib.security.LegacyCode.decryptPassword(oldpass))
But when trying to do it with via the file:
Dim FILE_NAME As String = "C:\mydir\smart\myfile.DAT"
Dim objReader As New System.IO.StreamReader(FILE_NAME)
Dim encryptedPw As String = objReader.ReadToEnd
objReader.Close()
MsgBox(mylib.security.LegacyCode.decryptPassword(encryptedPw))
It is causing issues. While debugging the string in encryptedPw
doesn't look correct:
How do I get the string to read into a variable correctly?
Upvotes: 0
Views: 72
Reputation: 190
Have you tried to give the StreamReader a text encoding?
https://msdn.microsoft.com/de-de/library/system.io.streamreader(v=vs.110).aspx
As second parameter
StreamReader(YourStream, System.Text.Encoding.Default)
or System.Text.Encoding.UTF8 or System.Text.Encoding.ASCII ?
Upvotes: 3