I'm using the System.Security.Cryptography library to encrypt and decrypt xml files. Recently though I've been getting OOM (Out of Memory) exceptions while trying to decrypt a 75MB file. Here's the code I'm using:
using System.Security.Cryptography.Xml;
...
public static XmlDocument DecryptIntoXmlDoc(string filename)
{
//Decrypt the XML
XmlDocument xmldoc = new XmlDocument();
EncryptedXml exml = new EncryptedXml(xmldoc);
TripleDESCryptoServiceProvider ekey = new TripleDESCryptoServiceProvider();
ASCIIEncoding encoding = new ASCIIEncoding();
ekey.Key = encoding.GetBytes(GetMasterKey());
exml.AddKeyNameMapping("ekey", ekey);
xmldoc.Load(filename);
// -- THROWS THE OOM ERROR --
exml.DecryptDocument();
//Clear exml
exml = null;
return xmldoc;
}
As soon as .DecryptDocument() is called I get the following error:
Exception of type 'System.OutOfMemoryException' was thrown.
I haven't been able to find anyone else having this problem, but I have read that if the xml tags aren't properly named/nested, the file can be very large when loaded into memory. Would renaming my XML tags to shorter names reduce the size? Is there a way to nest xml tags to reduce the file size?
Is there anything else I could do?