Using the documentation here: I wrote the following code. Keep in mind I am using the zip 20 algorithm so that I can type in the password when attempting to open on a windows machine.
var _archive = new ZipArchive(zipFile, ArchiveOpenMode.CreateNew);
_archive.Password = zipPassword;
_archive.EncryptionAlgorithm = EncryptionAlgorithm.Zip20;
_archive.Add(fileName);
_archive.Close();
This code successfully password protects the file inside the zip folder, but allows you open the zip folder to view the files. How can I prevent someone from opening the zip file without knowing the password?
I tried other algorithms but they did not allow for native windows decryption via a popup box when you try to open it. For example, the aes128 Encrypted it just fine but the decryption would also have to be done via code which is not acceptable for clients.
Unfortunately, this is a limitation of the ZIP 2.0 encryption format, and of WinZip-compatible AES‑128, AES‑192, AES‑256 encryption methods as well.
PKWARE SES ("Strong Encryption Specification") does support this, but as far as I know it is not supported by most other ZIP tools (including native ZIP decryption in Windows). But unfortunately Rebex cannot add support for it, because PKWARE patented the format in the US and is refusing to grant licenses to third parties.
A commonly-used workaround is to zip the file two times - first, zip all the files and directories without encryption. Then, zip the resulting ZIP file, this time with encryption. One of these steps can be performed with compression level set to zero to prevent compressing the data twice.