Search code examples
c#dotnetzip

DotNetZip password error special characters


When I open the zip file with the following code (specifying the password), I can get the files inside.

If I open the archive using IZArc and set the password there, it tells me that the password is invalid.

What can be the reason for this issue?

using (var zip = new ZipFile())
{
            zip.Password = "ïÁ×éÖËØ";
            zip.Encryption = EncryptionAlgorithm.PkzipWeak;

            var fullTaxFormFilePath = @"C:\DETALHE.txt";
            zip.AddFile(fullTaxFormFilePath, "");

            zip.Save(@"C:\DETALHEZIP.zip");
 }

Solution

  • The problem is internally DotNetZip uses the IBM437 code page and not unicode when converting the password (look for StringToByteArray in the source here). The code page was originally the one in the IBM PC so it's possible that's why it was chosen by PkZip. Because DotNetZip uses this code page it means that some of those characters are mapped in strange ways due to fallback. For example your password maps to the following (ignore the ?, that's just cause those aren't real chars):

    ï - 0x8b - ?, Á - 0x41 - A, × - 0x78 - x, é - 0x82 - ?, Ö - 0x99 - ?, Ë - 0x45 - E, Ø - 0x4f - O.

    Unless IZArc uses the exact same fallback behaviour then you'll not be able decrypt the file. Unfortunately IZArc seems to be closed source so I can't verify what it uses.