0 votes
by (210 points)
edited by

(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
by (73.6k points)
Are you using built-in Windows extractor or something else to extract the ZIP archive?
by (210 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
by (73.6k 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
by (73.6k points)
selected by
 
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);
}
by (210 points)
Thank you very much for your help
...