EldoS | Feel safer!

Software components for data protection, secure storage and transfer

How do I encrypt multiple files into a single encrypted file?

Also by EldoS: CallbackFilter
A component to monitor and control disk activity, track file and directory operations (create, read, write, rename etc.), alter file data, encrypt files, create virtual files.
#15008
Posted: 11/10/2010 17:16:37
by Rafael Monasterio (Standard support level)
Joined: 11/10/2010
Posts: 1

I was curious to know if anyone has any C# examples of how to write multiple files into a single encrypted file? I want to package several hundred files into a single encrypted archive file. I am also curious if there are any known limitations on how large of a file I can create. Potentially the resulting encrypted archive could contain several hundred files that are 2 megabytes to 20 megabytes each in size.
#15012
Posted: 11/11/2010 01:31:03
by Eugene Mayevski (EldoS Corp.)

OpenPGP standard doesn't support encryption of multiple files. PGP Corporation offered a handy way to bypass this problem - put all files to TAR archive, then encrypt TAR archive. ElPGPWriter supports this scheme, however TAR archive is created as a temporary stream.

You need to use EncryptFiles(NameList, StreamList, null, OutputStream) method and also handle OnTemporaryStream and create a temporary stream on the disk. If you don't do this, the temporary stream will be created in memory and with your file sizes you'll get OutOfMemory exception.

NameList is of type TStringList, declared in SBStringList namespace.


Sincerely yours
Eugene Mayevski
#15092
Posted: 11/22/2010 07:40:57
by Anne Wright (Basic support level)
Joined: 11/22/2010
Posts: 4

Do you have any examples on how to use the EncryptFiles or EncryptandSignFiles methods as when I try to use them I get a message saying the pgp file is corrupt.

I can successfully encrypt and sign a single file, but cannot get it to do the same for more than one file.
#15093
Posted: 11/22/2010 07:48:30
by Ken Ivanov (EldoS Corp.)

Thank you for contacting us.

Quote
...I get a message saying the pgp file is corrupt.

What exactly software does produce the above message?
#15094
Posted: 11/22/2010 08:02:20
by Anne Wright (Basic support level)
Joined: 11/22/2010
Posts: 4

'PGP Desktop' which is what I use to decrypt the PGP File
#15095
Posted: 11/22/2010 08:09:22
by Eugene Mayevski (EldoS Corp.)

Please show your code first of all. Without seeing the code it's hard to say anything.


Sincerely yours
Eugene Mayevski
#15096
Posted: 11/22/2010 08:14:56
by Anne Wright (Basic support level)
Joined: 11/22/2010
Posts: 4

Please find below the code I use. The single file option works fine, but I have not been able to get the multi file option to work after trying many different ways.
[code]
PGPWriter.Timestamp = DateTime.Now;
PGPWriter.UseNewFeatures = UseNewFutures;
PGPWriter.UseOldPackets = UseOldPackets;

string filePath = FileSourcePath; //.Substring(0, FileSourcePath.IndexOf("*") - 1);
if (!filePath.EndsWith("\\"))
{
filePath = filePath + "\\";
}

string fileSpec = FileSourceFilename;
SBStringList.TElStringList source = new SBStringList.TElStringList();
ArrayList sourceList = new ArrayList();
//Stream destStream = null;

foreach (var sourceFile in Directory.GetFiles(filePath, fileSpec))
{
inF = new FileStream(sourceFile, FileMode.Open);
source.Add(sourceFile.Replace(filePath, ""));
sourceList.Add(inF);
inF.Flush();
inF.Close();
inF.Dispose();
}
if (source.Count == 1)
{
// set file info
info = new FileInfo(filePath + fileSpec);
PGPWriter.Filename = info.Name;
PGPWriter.InputIsText = false;

PGPWriter.EncryptAndSignFile(filePath + fileSpec, FileDestinationPath + CompressedFileName);
}
else
{
Stream destStream = new FileStream(FileDestinationPath + CompressedFileName, FileMode.OpenOrCreate);

PGPWriter.EncryptAndSignFiles(source, sourceList, filePath + CompressedFileName, destStream);
//PGPWriter.EncryptFiles(source, sourceList, FileDestinationPath + CompressedFileName, outF);

destStream.Close();
destStream.Dispose();
}
#15097
Posted: 11/22/2010 09:54:42
by Mykola Olshevsky (Basic support level)
Joined: 07/07/2005
Posts: 450

Hi.
1) What values .UseNewFeatures and .UseOldPackets have?
2) Have you tried to open produced file with PGPFilesDemo?
3) Can you call .EncryptAndSignFiles on some dummy files, with EldoS sample keys, and attach that file here, to investigate it?
#15098
Posted: 11/22/2010 10:01:45
by Anne Wright (Basic support level)
Joined: 11/22/2010
Posts: 4

Thank you for your help

1) What values .UseNewFeatures and .UseOldPackets have?
2) Have you tried to open produced file with PGPFilesDemo?

UseNewFeatures = false
UseOldPackets = true

Where will I find the PGPFilesDemo?

Best regards

Anne
#15099
Posted: 11/22/2010 10:08:32
by Mykola Olshevsky (Basic support level)
Joined: 07/07/2005
Posts: 450

It is available within SecureBlackbox distribution, by default it is installed to Documents\EldoS\SecureBlackbox.NET\Samples\C#\OpenPGPBlackbox\PGPFilesDemo
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.

Reply

Statistics

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