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

422 Views Asked by At

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?

2

There are 2 best solutions below

0
On BEST ANSWER

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

2
On

UPDATE:

The client used Windows OS built-in ZIP extractor to extract the produced ZIP archive. Unfortunately, Windows OS extractor is not capable of AES encryption, which caused the mentioned error. More details and possible solutions can be found at Rebex forum.


The error 'Windows cannot complete the extraction. The destination file could not be created' indicates that the file name contains some invalid characters for current platform. In your sample code you used strDataFilewithTimeStamp as file name argument, which probably contains colon ':', which is invalid character for file name on Windows.

It depends on the extractor what will be displayed in this case (password dialog or error).

To solve the issue, please ensure that the file name doesn't contain any of the invalid characters on Windows (please check the System.IO.Path.GetInvalidFileNameChars() method on Windows platform).