EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Encrypting large file -- IOException : Stream was too long.

Also by EldoS: Solid File System
A virtual file system that offers a feature-rich storage for application documents and data with built-in compression and encryption.
#19012
Posted: 02/13/2012 11:24:10
by John Morales (Standard support level)
Joined: 05/12/2011
Posts: 3

Hi,

I'm trying to encrypt a large file using a public key received by a client. The file is 3.1 gigs and after 4 hours I received an exception 'System.IO.IOException : Stream was too long.' Unfortunately I do not have the stack trace anymore, but I'm running it again with a smaller (2.7gig) file and will post the stack trace if that's helpful.

Here is the code I'm using:
Code
__Global.SetLicenseKey(ConfigurationManager.AppSettings["EldoS.SecureBlackbox.LicenseKey"]);
var pgpWriter = new TElPGPWriter();
pgpWriter.EncryptionType = TSBPGPEncryptionType.etPublicKey;
string publicKeyFile = OUTPUT_DIRECTORY + @"PublicKey.asc";
var publicKey = new TElPGPPublicKey();
publicKey.LoadFromFile(publicKeyFile);
var keyring = new TElPGPKeyring();
keyring.AddPublicKey(publicKey);
pgpWriter.EncryptingKeys = keyring;
pgpWriter.Compress = false;
pgpWriter.CompressionAlgorithm = SBPGPConstants.__Global.SB_PGP_ALGORITHM_CM_UNCOMPRESSED;
pgpWriter.CompressionLevel = 0;
pgpWriter.SymmetricKeyAlgorithm = SBPGPConstants.__Global.SB_PGP_ALGORITHM_SK_3DES;
pgpWriter.Protection = TSBPGPProtectionType.ptNormal;
pgpWriter.UseNewFeatures = false;
pgpWriter.UseOldPackets = true;
pgpWriter.EncryptFile(checkFileName, OUTPUT_DIRECTORY + @"Encrypted.txt");
#19013
Posted: 02/13/2012 11:45:50
by Ken Ivanov (EldoS Corp.)

Thank you for contacting us.

For the files of such size it makes sense to use temporary streams. Please handle the TElPGPWriter.OnTemporaryStream event, and create a FileStream object pointing to a temporary disk file inside the handler.

If OnTemporaryStream event is not handled, the components use memory streams for storing temporary data, which may lead to overflows if huge amounts of information are processed.
#19014
Posted: 02/13/2012 11:49:11
by Eugene Mayevski (EldoS Corp.)

Also, if OnTemporaryStream doesn't work for you, please specify what exactly version of SecureBlackbox you are using.


Sincerely yours
Eugene Mayevski
#19015
Posted: 02/13/2012 12:18:40
by John Morales (Standard support level)
Joined: 05/12/2011
Posts: 3

Thanks for the quick response. I will try using the temporary stream and let you know.

I'm using 8.2.197.40719
#19021
Posted: 02/13/2012 16:00:00
by John Morales (Standard support level)
Joined: 05/12/2011
Posts: 3

Ok, I think it worked, the process only took 20 minutes now instead of 4 hours, and no exceptions so that's a good sign.

I can't really tell if it worked since I would need the client to validate that they can decrypt it..

Here is the code that I used, if I did something dumb let me know:

Code
__Global.SetLicenseKey(ConfigurationManager.AppSettings["EldoS.SecureBlackbox.LicenseKey"]);
var pgpWriter = new TElPGPWriter();
pgpWriter.EncryptionType = TSBPGPEncryptionType.etPublicKey;
string publicKeyFile = OUTPUT_DIRECTORY + @"PublicKey.asc";
var publicKey = new TElPGPPublicKey();
publicKey.LoadFromFile(publicKeyFile);
var keyring = new TElPGPKeyring();
keyring.AddPublicKey(publicKey);
pgpWriter.EncryptingKeys = keyring;
pgpWriter.Compress = false;
pgpWriter.CompressionAlgorithm = SBPGPConstants.__Global.SB_PGP_ALGORITHM_CM_UNCOMPRESSED;
pgpWriter.CompressionLevel = 0;
pgpWriter.OnTemporaryStream += (object sender, ref Stream stream, ref bool finish) =>
{
  stream = new FileStream(Path.Combine(OUTPUT_DIRECTORY, Path.GetFileName(Path.GetTempFileName())), FileMode.OpenOrCreate);
  finish = true;
};
pgpWriter.SymmetricKeyAlgorithm = SBPGPConstants.__Global.SB_PGP_ALGORITHM_SK_3DES;
pgpWriter.Protection = TSBPGPProtectionType.ptNormal;
pgpWriter.UseNewFeatures = false;
pgpWriter.UseOldPackets = true;
pgpWriter.EncryptFile(checkFileName, OUTPUT_DIRECTORY + @"Encrypted.txt");
#19022
Posted: 02/13/2012 16:22:02
by Ken Ivanov (EldoS Corp.)

Just to confirm, you did everything correctly.
Also by EldoS: Rethync
The cross-platform framework that simplifies synchronizing data between mobile and desktop applications and servers and cloud storages

Reply

Statistics

Topic viewed 1596 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!