There's an old web application developed in vb.net and 2.0 Framework. The application reads an encrypted information of sql server name which are stored in a Windows registry. When it comes to this line of code
ConnectionStr = Encoding.ASCII.GetString(plainText)
i receive question marks within the string
"P??ARSMEYVDE02"
and it should be
"PLWARSMEYVDE02"
I tried to change the encoding to UTF8, Default or Unicode but with no luck. Here's the function
Public Function HostLogOnParameters() As Boolean
Try
Dim rk As RegistryKey = Registry.LocalMachine.OpenSubKey(ConfigurationSettings.AppSettings("Registry.LocalMachine") & "Host", False)
Dim ConnectionStr As String = rk.GetValue("1")
Dim initVector As String = rk.GetValue("2")
Dim strKey As String = rk.GetValue("3")
Dim dec As New Decryptor
dec.Decryptor(EncryptTransformer.EncryptionAlgorithm.TripleDes)
dec.IV = Convert.FromBase64String(initVector)
'Decrypt the string
Dim plainText As Byte() = dec.Decrypt(Convert.FromBase64String(ConnectionStr), Convert.FromBase64String(strKey))
ConnectionStr = Encoding.ASCII.GetString(plainText)
ConnectionStr = ConnectionStr.Substring(1)
mstrServer = Left(ConnectionStr, InStr(ConnectionStr, "'") - 1)
ConnectionStr = ConnectionStr.Substring(mstrServer.Length + 3)
mstrDatabase = Left(ConnectionStr, InStr(ConnectionStr, "'") - 1)
ConnectionStr = ConnectionStr.Substring(mstrDatabase.Length + 3)
mstrUser = Left(ConnectionStr, InStr(ConnectionStr, "'") - 1)
ConnectionStr = ConnectionStr.Substring(mstrUser.Length + 3)
mstrPassvord = Left(ConnectionStr, InStr(ConnectionStr, "'") - 1)
Return True
Catch ex As Exception
Return False
End Try
End Function
An output from the plainText as hexadecimals.
2750CCD74152534D45595644455630325C44455656533032272C2745594372797374616C486F73744244272C274372797374616C486F737455736572272C273132337265706F7274696E6721402327