Okay, now I realize what is happening. The literal data object is getting destroyed and in the process closes its member - the stream. As the code below resides in a wrapper library that is used for abstraction, so that the application would not need to know anything about BouncyCastle and would only operate in terms of the standard .NET streams, using the stream after literal data has gone out of scope would be impossible.
It sounds like GetInputStream() methods of PGPLiteralData and LiteralDataPacket should be overloaded to receive an output parameter of Stream. The user can then pass their own Stream and use it independent of the literal data object lifetime. But even then LiteralDataPacket closes the stream when it goes out of scope and this application is SOL. Do you have an example of decrypting the files larger than available RAM without writing unencrypted data to disk? Thank you! Alex -----Original Message----- From: Alex Malmyguine [mailto:alex.malmygu...@bluesun.ca] Sent: Wednesday, June 01, 2016 5:34 PM To: dev-crypto-csharp@bouncycastle.org Subject: [dev-crypto-csharp] Decrypting a very large PGP file w/o using a MemoryStream 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