469,575 Members | 1,640 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,575 developers. It's quick & easy.

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 3891
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Stingray | last post: by
5 posts views Thread by weixiang | last post: by
reply views Thread by Daniel Weber | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.