Unable to properly create the password protected zip file using Rebex library

0 votes
asked Dec 31, 2018 by mpodolski (150 points)
edited Jan 3 by Lukas Matyska

(Note: originally asked at stackoverflow.com)

I am trying to create a password protected zip file using the Rebex libraries.

Here is the code that I use

            using (ZipArchive zip = new ZipArchive("C:\\Temp\\Ticket.zip", ArchiveOpenMode.Create))
        {
            // Set the Password first
            zip.Password = "my_password";

            // Change the default Encryption algorithm
            zip.EncryptionAlgorithm = EncryptionAlgorithm.Aes256;

            // Add the file to newly created "files" folder within the zip file
            zip.AddFile("C:\\temp\\Ticket.JPG");

            //Save the Zip file
            zip.Save();

            // cloase the zip file
            zip.Close();
        }

However, when I try to open the file I don't get the expected 'Password needed' dialog.

Instead I get the error message saying 'Windows cannot complete the extraction. The destination file could not be created'

I do need to get the expected 'Password needed' dialog so that I could properly extract the file

Please let me know if anyone ever dealt with that issue and found the solution

Applies to: Rebex ZIP
commented Jan 2 by Lukas Matyska (52,710 points)
Are you using built-in Windows extractor or something else to extract the ZIP archive?
commented Jan 2 by mpodolski (150 points)
Lukas, we are not really using an extractor. We just download the zipped up file and extract its contents using the windows OS

Please let me know if you have additional questions
commented Jan 3 by Lukas Matyska (52,710 points)
I understand. Your answer "extract its contents using the windows OS" means that you are using built-in Windows OS extractor, which is not capable of EncryptionAlgorithm.Aes256.

Please see my answer below (http://forum.rebex.net/9578/unable-properly-create-password-protected-using-rebex-library?show=9583#a9583).

1 Answer

0 votes
answered Dec 31, 2018 by Lukas Matyska (52,710 points)
selected Jan 8 by mpodolski
 
Best answer

It showed that the problem is in Windows extractor itself. You are using EncryptionAlgorithm.Aes256 to encrypt the ZIP archive, which is good choice, but this encryption algorithm is not supported by Windows extractor (please check this and this).

The only encryption algorithm Windows extractor supports is legacy EncryptionAlgorithm.Zip20 algorithm, which is not secure in present (you can check it here).

The suggested solution is to use EncryptionAlgorithm.Aes256 algorithm to protect the ZIP archive and use a third party application to extract it. You can do it using Rebex Zip like this:

using (ZipArchive zip = new ZipArchive("C:\\Temp\\Ticket.zip", ArchiveOpenMode.Open))
{
    zip.Password = "my_password";

    zip.ExtractAll("C:\\temp", TransferMethod.Copy, ActionOnExistingFiles.OverwriteAll);
}
commented Jan 8 by mpodolski (150 points)
Thank you very much for your help
...