This is what I’m doing to encrypt a pdf file:
FileStream input = new FileStream(filename, FileMode.Open, FileAccess.Read);
FileStream output = new FileStream(filename + “.aspose.enc.pdf”, FileMode.Create, FileAccess.Write);
PdfFileSecurity fileSecurity = new PdfFileSecurity();
fileSecurity.EncryptFile(“pass1”, “pass”, DocumentPrivilege.AllowAll, KeySize.x128, Algorithm.RC4);
Problem is, when the function fileSecurity.EncryptFile gets called, the entire pdf document gets loaded into memory. And on the next line fileSecurity.Save, more memory gets used. So to encryption a 80MB file, using RC4-128bit will use up 155MB of memory. Using AES-128bit will use up 322MB of memory, which is even worse.
Is there a different way to do this so that the encryption is really done on the fly and not by loading the whole document into memory? I’m using PDF for .net version with dll file version 188.8.131.52, product version 2012.08.28