The application I inherited was used with relatively reasonable files that fit entirely into available RAM so far, but it will have to decrypt the larger files in the future. I could overcome the immediate problem this creates - that there may not be enough contiguous RAM for the content - using a custom MemoryStream class. But the requirement is to avoid decrypted data being swapped out into the page file, so I cannot use this approach as content may be larger than available RAM.
Currently the app is using the following code: PgpObjectFactory plainFact = new PgpObjectFactory(clearStream); PgpObject message = plainFact.NextPgpObject(); if (message is PgpLiteralData) { PgpLiteralData literalData = null; literalData = (PgpLiteralData)message; MemoryStream decryptedStream = new MemoryStream(); literalData.GetInputStream().CopyTo(decryptedStream); return decryptedStream; } And then the application will read line by line from the memory stream and process data. There will be a problem if the decrypted data does not fit entire into RAM. I tried replacing this with straight returning of the input stream: PgpObjectFactory plainFact = new PgpObjectFactory(clearStream); PgpObject message = plainFact.NextPgpObject(); if (message is PgpLiteralData) { PgpLiteralData literalData = null; literalData = (PgpLiteralData)message; return literalData.GetInputStream(); } But when I tried creating a TextReader from that stream and calling ReadToEnd(), the application threw an exception: System.ObjectDisposedException: Cannot access a closed file. How can I read string data line by line from the stream returned by PgpLiteralData. GetInputStream()? Thank you! Alex