Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't Windows 7 extract files from my password protected zip-file created using DotNetZip?

Tags:

c#

.net

dotnetzip

I'm creating a password protected zip-file using DotNetZip. When I try to extract the files I'm met with an "unspecified error". Why is that?

using (var zipFile = new ZipFile())
{
    zipFile.Encryption = EncryptionAlgorithm.WinZipAes256;
    zipFile.Password = "pangolin";

    foreach(var file in someFileCollection)
    {
        zipFile.AddEntry(file.Name, file.Stream);
    }

    zipFile.Save(aPathOnDisk);
}
like image 614
J. Steen Avatar asked Mar 24 '15 15:03

J. Steen


1 Answers

This is because Windows and more specifically Windows Explorer can't handle AES-level encryption and requires the encryption level to be set to PkzipWeak which is documented as "Traditional or Classic pkzip encryption."

zipFile.Encryption = EncryptionAlgorithm.PkzipWeak;

According to the documentation on the EncryptionAlgorithm enumeration:

[...] if you produce a zip archive using WinZipAes256, you will be able to open it in Windows Explorer on Windows XP and Vista, but you will not be able to extract entries; trying this will lead to an "unspecified error".

Note: popular third-party archive-utilities such as WinZip or 7-Zip can handle AES-encryption just fine. It's Windows Explorer that's the weak card in the deck.

like image 128
J. Steen Avatar answered Sep 30 '22 23:09

J. Steen