472,331 Members | 1,469 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,331 software developers and data experts.

C#: XmlTextReader with CryptoStream

I have the following code that's taken and modified from a got_dot_net
example.

I'm trying to decrypt an Xml file that's been encrypted. I can dump the
decrypted stream to the console, but if I try to load that into
XmlTextReader, it throws XmlException. I'd appreciate your help.

//create file stream to read encrypted file back
FileStream fsread = new FileStream(args[0], FileMode.Open,
FileAccess.Read);

//DES instance with random key
DESCryptoServiceProvider des = new DESCryptoServiceProvider();

//create DES Decryptor from our des instance
ICryptoTransform desdecrypt =
des.CreateDecryptor(SymmetricKeyForDimeData.Secret Key,
SymmetricKeyForDimeData.InitializationVector);

//create crypto stream set to read and do a des decryption transform on
incoming bytes
CryptoStream cryptostream = new CryptoStream(fsread, desdecrypt,
CryptoStreamMode.Read);

StreamReader streamreader = new StreamReader(cryptostream, new
UTF8Encoding());

//Console.Write(streamreader.ReadToEnd()); // this works.

XmlTextReader xtr = new XmlTextReader(cryptostream);
xtr.WhitespaceHandling = WhitespaceHandling.None;
xtr.XmlResolver = null;

// this causes System.Xml.XmlException: The root element is missing.
while(xtr.Read()) {
Console.WriteLine("Element Name: {0}", xtr.Name);
}

Nov 17 '05 #1
2 4002
Have you tried:
string xmlInput = streamReader.ReadToEnd();

XmlTextReader xtr = new XmlTextReader(xmlInput);

Nov 17 '05 #2
Yes. It didn't work.

Adam wrote:
Have you tried:
string xmlInput = streamReader.ReadToEnd();

XmlTextReader xtr = new XmlTextReader(xmlInput);


Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Stingray | last post by:
Are there any know problems with using a MemoryStream as a backing store for a CryptoStream? I'm trying to simply encrypt and decrypt text in...
8
by: MattP | last post by:
Ok, with the help of some examples found on the web and some minor modifications on our own, we have a simple and working encrypt and decrypt...
1
by: Casey Watson | last post by:
Hi :) I'm having some major trouble with an XML Client/Server application that I am writing. I am using NetworkStream with CryptoStream to Read...
5
by: weixiang | last post by:
Hi, I want to use DES and CryptoStream to serialize a encrypted stream to a file with a header "CRYPT". And I wrote these code: To store: ...
0
by: Daniel Weber | last post by:
Hi! In my code I create a CryptoStream around another stream of my own, with CryptoStreamMode.Read. So I just can read from the CryptoStream....
6
by: Tim Barg | last post by:
I am using a CryptoStream to encrypt and then save an xml file. However, when reading it back in, I am getting a CryptographicException. I am...
7
by: semedao | last post by:
Hi, I am using cryptostream on both sides on tcp connection that pass data. I am also use asyc socket , so , the data that recieved in the callback...
9
by: TC | last post by:
Hey All, I posted this to the Crypto users group and forgot to add the VB.Net users group. I apologize for any confusion. I have been testing...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.