EldoS | Feel safer!

Software components for data protection, secure storage and transfer

TElPGPReader Memory Usage

Also by EldoS: Callback File System
Create virtual file systems and disks, expose and manage remote data as if they were files on the local disk.
Posted: 08/27/2007 12:46:13
by Matthew Dragiff (Standard support level)
Joined: 03/01/2007
Posts: 15


I'm trying to use SecureBlackBox's OpenPGP Encryption to decrypt files in a BizTalk solution and I'm running into out of memory exceptions when the file I'm trying to decrypt approaches an (encrypted) size of around 20-25 MB (decrypted ~130-180 MB). I extracted my code into a simple winforms app that simply takes a file and performs the decryption, and memory usage hits 1GB during the decryption. Is this normal?

I'm using version

Here are the guts of my Decryption code:

public System.IO.Stream Decrypt()
SBPGPKeys.TElPGPKeyring pgpKeyRing = new SBPGPKeys.TElPGPKeyring();

//These are stream objects that are members of the class this
//method resides in. InputStream is a System.IO.FileStream in
//this case.
InputStream.Seek(0, SeekOrigin.Begin);
PublicKey.Seek(0, SeekOrigin.Begin);
PrivateKey.Seek(0, SeekOrigin.Begin);

pgpKeyRing.Load(PublicKey, PrivateKey, true);
SBPGPKeys.TElPGPKeyring pgpPublicKey = new SBPGPKeys.TElPGPKeyring();
for (int i = 0; i < pgpKeyRing.PublicCount; i++)

SBPGPKeys.TElPGPKeyring pgpSecretKey = new SBPGPKeys.TElPGPKeyring();
for (int i = 0; i < pgpKeyRing.PublicCount; i++)
pgpSecretKey.get_SecretKeys(i).Passphrase = PassPhrase;

_pgpReader.DecryptingKeys = pgpSecretKey;
_pgpReader.VerifyingKeys = pgpPublicKey;

//_sDecryptedStream is a System.IO.MemoryStream
_pgpReader.OutputStream = _sDecryptedStream;
_pgpReader.OnCreateOutputStream += new TSBPGPCreateOutputStreamEvent(pgp_OnCreateOutputStream);
_pgpReader.KeyPassphrase = PassPhrase;
_pgpReader.DecryptAndVerify(InputStream, 0);

return _sDecryptedStream;

private void pgp_OnCreateOutputStream(object sender, string Filename, DateTime TimeStamp, ref Stream Stream, ref bool FreeOnExit)
Stream = _sDecryptedStream;
FreeOnExit = false;
Posted: 08/27/2007 13:27:11
by Ken Ivanov (EldoS Corp.)

Is this normal?

Actually, no. Please try to decrypt the file to System.IO.FileStream and check if decryption exposes the same memory usage values. It is also a good idea to upgrade to the latest available build update and try your code with it.
Posted: 08/27/2007 13:46:27
by Matthew Dragiff (Standard support level)
Joined: 03/01/2007
Posts: 15

I found the problem. Almost immediately after posting, actually. Changing _sDecryptedStream to a FileStream took care of the problem.



Topic viewed 1879 times

Number of guests: 1, registered members: 0, in total hidden: 0


Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!