WinZip cannot open ZIP that uses PkzipWeak password protection

Jul 30, 2009 at 9:24 PM

Hi,

I have the following code which creates a zip file with a password. However, when I extract it, it's not asking for any kind of password. Please let me know, how to resolve this issue.

 

             

                Response.Clear();
                Response.BufferOutput = false;
                string archiveName = String.Format("archive-{0}.zip",
                                                  DateTime.Now.ToString("yyyy-MMM-dd-HHmmss"));
                Response.ContentType = "application/zip";
                Response.AddHeader("content-disposition", "attachment; filename=" + archiveName);

                using (ZipFile zip = new ZipFile())
                {
                    zip.AddFile(@"C:\Test.xls", "Zipped");
                    zip.Password = "123456!";
                    zip.Save(Response.OutputStream);
                }

                HttpContext.Current.ApplicationInstance.CompleteRequest();

Jul 30, 2009 at 9:45 PM

Hi,

You have to set password before adding the files.

using (ZipFile zip = new ZipFile())
{

   zip.Password = "123456!";
   zip.AddFile(@"C:\Test.xls", "Zipped");
   zip.Save(Response.OutputStream);
}

Jul 30, 2009 at 10:00 PM

Thanks ,It's now asking for password. But it's not accepting whatever password I provide.

using (ZipFile zip = new ZipFile())
                {
                    zip.Password = "123456";
                    zip.AddFile(@"C:\Test.xls", "Zipped");
                    zip.Save(Response.OutputStream);
                }

When I extract the Zipped Archive, it throws an error saying wrong password. What am I doing wrong here?

 

Coordinator
Jul 30, 2009 at 10:12 PM

I don't know what you're doing wrong.  A couple things could be happening:

  • in an earlier version of DotNetZip there was a problem saving password-protected files to a nonseekable stream, like Response.OutputStream in ASP.NET.  That problem was fixed.  If you are using the latest library you won't have this problem.
  • maybe there is a code problem in your extract logic?

did you try unpacking it with Windows Compressed Folders or winzip or some other password-aware zip archive tool?  do you get the same results there?

 

Jul 30, 2009 at 10:20 PM

Hi Cheeso,

I am using the latest version of DotNetZip (V 1.8). I downloaded the MSI and installed it. And I copied the Ionic.Zip.dll into my project folder and I am using this dll.

I tried with WinZip and WinRar , both of them give the same error saying password is wrong. Without Password, I am able to extract and view the file.

 

Below is the Complete Extraction Logic:

 Response.Clear();
 Response.BufferOutput = false;
 string archiveName = String.Format("archive-{0}.zip",
                                DateTime.Now.ToString("yyyy-MMM-dd- 
                                                                                  HHmmss"));
 Response.ContentType = "application/zip";
 Response.AddHeader("content-disposition", "attachment;  
                                                        filename=" + archiveName);

 using (ZipFile zip = new ZipFile())
 {
    zip.Password = "123456";
    zip.AddFile(@"C:\Test.xls","Zipped");
    zip.Save(Response.OutputStream);
 }
HttpContext.Current.ApplicationInstance.CompleteRequest();

Thanks

Abhijith

Coordinator
Jul 31, 2009 at 1:24 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Jul 31, 2009 at 1:30 AM

Hi Cheeso,

Thanks for the update. How will this discussion proceed now? Should I do anything now? I mean, I already have the issue put down. Will anyone try to solve that issue and update me?

I am not sure how this Issue tracker works.

 

 

Coordinator
Jul 31, 2009 at 4:35 AM
Edited Jul 31, 2009 at 4:39 AM

I've produced a fix.  The problem occurred only when zip files get saved to non-seekable streams, like ASPNET's Response.OutputStream. There is a section in the zip specification dealing with non-seekable streams that says "applications sometimes do X and sometimes do Y", in regards to formatting of the zip file.  The specification also said "tools should be able to read either format."  Well DotNetZip did X, and was able to READ either format, according to the spec.  But WinZip was not able to read either format.  It expected format Y. 

The way to fix this is to modify DotNetZip to conform to the format that WinZip expects.  It's a pretty simple fix.  But that change means I have to write a bunch of new tests to verify that the zipfiles DotNetZip produces are compatible with WinZip, 7zip, and a bunch of other libraries.

That is all done now. I am producing the release now.  In a few moments you'll be able to download it and test it yourself.

I'll let you know.

Coordinator
Jul 31, 2009 at 4:45 AM

ok, download v1.8.4.14, it has the fix you need.

 

Jul 31, 2009 at 3:00 PM

Hi Cheeso,

It works like a charm!!! Thanks for the quick fix.

 

Coordinator
Jul 31, 2009 at 4:19 PM

you're welcome. thanks for reporting the problem.

Jul 31, 2009 at 11:08 PM

Hey,

I noticed that you've changed the title as: "WinZip cannot open ZIP that uses PkzipWeak password protection". But on the contrary, I am able to extract files with PkzipWeak and not with any of the WinZipAes types.

It gives the following message:

 

Extracting to "C:\DOCUME~1\LOCALS~1\Temp\"
Use Path: no   Overlay Files: yes
skipping: Zipped/USReports.xls    unsupported compression method 99
error:  no files were found - nothing to do

Coordinator
Aug 1, 2009 at 8:14 AM
Edited Aug 1, 2009 at 11:59 PM

Hey Abhijith,

The problem I fixed, based on this thread, was that WinZip could not open ZIP files generated by DotNetZip, which used PkzipWeak encryption, and which were streamed out to ASPNET's Response.OutputStream.

I also understand that you confirmed that this problem was, in fact, fixed, with the changes I made. ("It works like a charm.")

If that's not your understanding, please advise.

if you have a new, different problem, then you should open a new thread.

EDIT: I have a bunch of tests for WinZip AES encryption, including tests for producing a WinZIP AES-encrypted ZIP file from within an ASP.NET web page. All those tests pass. I can read such a zip with WinZip.

So, in the new thread you create, describing the new problem you're having, you will need to give me some additional information about the problem, how you can make it happen, what tool you are using to unzip, etc. Compression method 99 is the method for AES-encrypted zip files.  So if your tool says it is not supported, it's possible that it just doesn't know how to open AES files. Maybe you're on a trial version or something.