Note that there are some explanatory texts on larger screens.

plurals
  1. PORead/decrypt encrypted XML file and then process internally
    text
    copied!<p>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.</p> <p>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.</p> <p>Please help, thanks!</p> <h2>Encrypt</h2> <pre><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></pre> <h2>DECRYPT</h2> <pre><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></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload