I'm writing a Vb.Net application that reads an encrypted XML file from a PHP server. I'm using the code snippets found here:
PHP Encryption & VB.net Decryption
specifically Richard Varno's answer and code. I can compare the original XML file on the PHP server to the decrypted version on VB.Net and they are identical.
The problem is that when I load the decrypted version into an XML document in Vb.Net I just get an empty document.
If I load the unencrypted version from the PHP server it's fine. I can't see any obvious difference between the two other than that one has been encrypted and then de-encrypted. Both are strings, and both have been Gzipped so why would this not work ?
Here's my code to read in the unencrypted string:
Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create(lookupUrl)
' Tell the server that we want it compressed
request.AutomaticDecompression = DecompressionMethods.GZip
request.Timeout = 3000 ' Set 3 second timeout
' Parse the contents from the response to a stream object
stream = response.GetResponseStream()
' Create a reader for the stream object
Dim reader As New StreamReader(stream)
' Read from the stream object using the reader, put the encrypted contents in a string
Dim contents As String = reader.ReadToEnd()
' Put de-encrypted contents into another string
Dim decrypted As String = ""
' Create a new, empty XML document
Dim document As New System.Xml.XmlDocument()
Console.WriteLine("Received: " & contents)
' De-encrypt the data from the response from the server
decrypted = DecryptRJ256(Globals.sKy, Globals.sIV, contents)
Console.WriteLine("Decrypted: " & decrypted)
' Load the contents into the XML document
document.LoadXml(contents)
Dim nodes As XmlNodeList = document.DocumentElement.SelectNodes("//results/Node1")
Now the above works but if I replace
document.LoadXml(contents)
with:
document.LoadXml(decrypted)
my XML document is empty.