[OpenPGP] Error while decryption using openpgp
Service icon
Forge component by João Barata

Hi  All,

This component is awesome, But when we encrypt a file with more that 20 kb we face  a issue  while decryption the  file. The error  message was "Cannot access a closed Stream." . Please provide a  solution for this issue.


Arun kumar

Hi Arun

did you get any solution to this one?

Hi Nischitha,

It is not possible to decrypt a file which size is more than a certain size, I'm not sure about the threshold size but in my case, I faced this error for a 21 kb file. I  just encoded the image stored it in my DB in my case.


Arun Kumar

Anyone found a solution to this?

@Stephen, Jie Hui Yeo 

Looks like the issue comes from closing the input stream before reading it.  I put together a quick work around which seems to fix the issue for me.  If you do the same, you'll need to open it in integration studio and modify the code.

The code in question is in the OpenPGP project in the PGPUtilities.cs file. Starting at line 171 you'll see the following

I've modified it to the following

Code in plain text is:

Stream finalInputStream = new MemoryStream();

if (dataObject != null)
    (dataObject as PgpLiteralData).GetInputStream()

foreach (var layeredStream in layeredStreams)

return finalInputStream;


Dear Paul,

Thank you for providing the workaround here. somehow I tried to apply your solution but the function still promotes the same error "Cannot access a closed Stream. "

I have another solution here and it works for me to decrypt any file over 20kb. If anyone here looking for a solution then you may try this.

Please see my attachment(txt file) and replace these codes with:

    File name: PGPUtilities.cs

    Function name: public static Stream PgpDecrypt (start from row 103)




Hi Jack,

Please request to be added to the team of this component so you can implement your solution directly.

I'll gladly add you to the team!


Hi Jack, thanks for sharing that.

I'll review it and add it to a new version of the component

@Jack Wong @Paul Giammarco @Arun Kumar

I've just released version 1.1.3 of the forge component which should address this issue.

I've also taken the opportunity to move the changes I had under development to this stable release.

Please check the release notes.


Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.