0

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

jambis
  • 122
  • 2
  • 10
  • @owlstead, not sure if I understand. Would you like me to print out results from this line Dim plainText As Byte() = dec.Decrypt(Convert.FromBase64String(ConnectionStr), Convert.FromBase64String(strKey)) ? – jambis Nov 29 '13 at 08:28
  • 1
    Yes, exactly that, [converted to hexadecimals](http://social.msdn.microsoft.com/Forums/vstudio/en-US/fa53ce74-fd53-4d2a-bc05-619fb9d32481/convert-byte-array-to-hex-string?forum=vbgeneral) of course, my brain is better in handling `20` instead of `0010 0000` or a simple " " character. – Maarten Bodewes Nov 29 '13 at 09:38
  • @owlstead, I added the output in the main post. – jambis Dec 01 '13 at 19:51

1 Answers1

0

It's probably in Latin (ISO 8859-1) because it then reads PÌ×ARSMEYVDEV02\DEVVS02, and Pixar is if course a well known company. Note that Windows-1252 is a superset of this character encoding.

Maarten Bodewes
  • 90,524
  • 13
  • 150
  • 263
  • Does this solve your question, jambis? If you think it doesn't you could try other character encodings. – Maarten Bodewes Dec 06 '13 at 15:57
  • sorry, I've completely forgotten about this. No, it doesn't solve my problem. I tried your suggestion but every time I'm getting a dirty read. That is an old application which will be decommissioned soon and it's is a test environment, so I moved the connection string into a web.config file. But anyway thank you for your help! – jambis Dec 08 '13 at 20:49
  • @jambis OK, shame this isn't the solution, your soon to be deprecated application may be losing or corrupting data in that case. All the more reason to sink it. You can delete the question if you think it is not of use to anyone else (otherwise it will stay unanswered). – Maarten Bodewes Dec 08 '13 at 21:02