login about faq

I tried to zip several files including an already zipped file into a zip object and set a password to it. For example, I'd like to create a new zip file with a text file wTxtToZip and a zipped file Azippedfile in it. And I need this new zip file to be password-protected. I’m using

objZip.AppendFiles(wTxtToZip, true);

But I found that with objZip.AppendZip(Azippedfile), the password is no longer set to the zip file. It works fine without it. I would love to know a solution to set a password to the zip file in this situation.

Thank anybody who would help very much in advance!

asked Jan 14 '15 at 20:30

Veda's gravatar image


The zip file format is such that there is no single header that defines the settings for all of the entries within a zip. The settings for each entry (file or directory), such as compression algorithm, compression level, encryption, and even the password*, are completely contained within the entry itself. (for example, see this: https://users.cs.jmu.edu/buchhofp/forensics/formats/pkzip.html )

The new files being written into a zip are those specified by AppendFiles (or AppendData). For these yet-to-be-created zip archive entries, the characteristics, such as encryption, compression level, etc. are determined by the properties of the CkZip object. When you append the already-existing entries of an already-existing Zip archive via AppendZip, the compression level and encryption settings for those entries won't change. Those entries are simply merged into the new zip that is created via WriteZipAndClose. Therefore, your code snippet above, the result would be a zip where the new entries are password protected, but the existing entries added via AppendZip are not.

The only solution would be to unzip the "Azippedfile" and then add the files.

*The password is not actually stored within the .zip. Instead, a checksum/hash of the password is saved in a header within the zip file format.


answered Jan 14 '15 at 22:06

chilkat's gravatar image

chilkat ♦♦

Thank you and I think it's quite necessary for me to study the structure of a zip file.

(Jan 14 '15 at 22:30) Veda
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: Jan 14 '15 at 20:30

Seen: 2,014 times

Last updated: Jan 14 '15 at 22:30

powered by OSQA