7

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);
}
J. Steen
  • 15,470
  • 15
  • 56
  • 63

1 Answers1

10

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.

J. Steen
  • 15,470
  • 15
  • 56
  • 63
  • Looks like 7-Zip can handle it, and I would guess WinZip and probably WinRar as well. – Joe Enos Mar 24 '15 at 15:50
  • @JoeEnos Yes. It's specifically Windows Explorer that's weak in this regard. – J. Steen Mar 24 '15 at 15:50
  • 2
    On a related note, if using 7zip to password protect an archive, you have to use encryption method "ZipCrypto" instead of "AES-256". This answer helped me figure that out. – Demonslay335 Jan 23 '17 at 15:21
  • 1
    Seems like Macs have the same problem as Windows. I didn't create the file, but I encountered one that both Windows and Mac would throw a permissions error on when trying to extract. WinRar was able to prompt for password and handle it properly. – Greg Smalter Jan 02 '19 at 15:47