Search code examples
c#rebex

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


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(ZipFilePath, ArchiveOpenMode.Create))
{
   // Set the Password first
   zip.Password = strUserPIN;

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

   // Add the file to newly created "files" folder within the zip file
   zip.AddFile(Temp_BPI_SaveLocation + strDataFilewithTimeStamp, @"\files\");

   //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

Has anyone ever dealt with that issue and found a solution?


Solution

  • Here is the answer I accepted from the Rebex forum

    "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."