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

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,

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

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

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

StreamReader streamreader = new StreamReader(cryptostream, new

//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

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...
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...
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...
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: ...
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....
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...
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...
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...
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....
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...
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...
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...
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...
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...
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...
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
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.