By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,103 Members | 1,524 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,103 IT Pros & Developers. It's quick & easy.

C#: XmlTextReader with CryptoStream

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
Have you tried:
string xmlInput = streamReader.ReadToEnd();

XmlTextReader xtr = new XmlTextReader(xmlInput);

Nov 17 '05 #2

P: n/a
Yes. It didn't work.

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

XmlTextReader xtr = new XmlTextReader(xmlInput);


Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.