Read/decrypt encrypted XML file and then process internally

Kawsteene

New Member
I have used this code in the past for writing and reading xml files. This time I want to write some encrypted generated XML and then read it and process it internally. I will post the code and perhaps someone can spot the problem.When I am testing the decrypt I have been able to output a file that has a continuous line of null character codes. The encrypted file seems to contain data and varys in size with different amounts of data.Please help, thanks!Encrypt\[code\]MemoryStream ms = new MemoryStream();XmlTextWriter xmlwriter = new XmlTextWriter(ms,Encoding.UTF8);FileStream EncryptedFileStream = new FileStream(file, FileMode.Create, FileAccess.Write);DESCryptoServiceProvider DES = new DESCryptoServiceProvider();DES.Key = ASCIIEncoding.ASCII.GetBytes("AAAAAAAA");DES.IV = ASCIIEncoding.ASCII.GetBytes("AAAAAAAA");ICryptoTransform desEncrypt = DES.CreateEncryptor();CryptoStream cryptostream = new CryptoStream(EncryptedFileStream, desEncrypt, CryptoStreamMode.Write);/*create working and tested XML data here*/byte[] bytearray = new byte[ms.Length];ms.Read(bytearray, 0, bytearray.Length);cryptostream.Write(bytearray, 0, bytearray.Length);cryptostream.Close();EncryptedFileStream.Close();xmlwriter.Close();ms.Flush();ms.Close();\[/code\]DECRYPT\[code\]MemoryStream ms = new MemoryStream();StreamWriter swDecrypt = new StreamWriter(ms);DESCryptoServiceProvider DES = new DESCryptoServiceProvider();DES.Key = ASCIIEncoding.ASCII.GetBytes("AAAAAAAA");DES.IV = ASCIIEncoding.ASCII.GetBytes("AAAAAAAA");ICryptoTransform desDecrypt = DES.CreateDecryptor();FileStream fsDecrypt = new FileStream(mstrIndexFile, FileMode.Open, FileAccess.Read);CryptoStream cryptostreamDecr = new CryptoStream(fsDecrypt, desDecrypt, CryptoStreamMode.Read);swDecrypt.Write(new StreamReader(cryptostreamDecr).ReadToEnd());swDecrypt.Flush();ms.Position = 0;\[/code\]
 
Back
Top