Exception on zipping and encrypted small file

Jul 1, 2009 at 6:08 PM

Hi all,

I'm a relatively new user of the DotNetZip library and I'm experiencing the following problem: When I try to zip a small file (eg. 3 bytes) and encrypt it as well I get the following error on the zip.Save statement:

An attempt was made to move the position before the beginning of the stream. ()

This error does not occur when the file content is larger or when the file is 0 bytes. However, when the size is zero bytes I don't seem to be able to open the file using the password. A 'CRC failed in encrypted file 'filename'. Wrong password ?' is generated. I'm sure the password is correct. When the file contains content this works ok.

Thanks for any help or pointers.

boris

This is the code snippet I'm using:

private static MemoryStream ZipAndEncryptReport(MemoryStream report, INotifierInstanceTemplate template, string filename)
{

if (template.ZipReport && template.Type != TemplateType.EmailContent)
{
MemoryStream zippedStream = new MemoryStream();
ZipFile zip = new ZipFile();
report.Seek(0,
SeekOrigin.Begin); <font size="2">

log.InfoFormat(

</font>

"The output for the report <{0}> is zipped.", filename);<font size="2">

 

</font>

 

if (template.EncryptReport)
{
log.InfoFormat(
"The output for the report <{0}> is encrypted with AES 256.", filename);<font size="2">

zip.Password = template.EncryptPassword;
zip.Encryption =

</font>

EncryptionAlgorithm.WinZipAes256;
}<font size="2">

zip.AddFileStream(filename,

</font>

"", report);
zip.Save(zippedStream);<font size="2">

 

</font>

 

return zippedStream;
}<font size="2">

 

</font>

}<font size="2">

 

</font>

 

return report;

}

Coordinator
Jul 1, 2009 at 7:39 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Coordinator
Jul 2, 2009 at 1:49 AM

Boris, I had an arithmetic error in the code. Can you try v1.8.4.1 ?