[
  {
    "Id": "586701",
    "ThreadId": "251268",
    "Html": "\r\n<p>Is there anyway to create a zip file with password protection on the complete file vs a password on the files contained within? I know this may not be spec but it seems silly to have to enter a password for each file.&nbsp; I want a password required when\r\n someone tries to open the zipfile itself.</p>\r\n<p>&nbsp;</p>\r\n<p>Thanks,</p>\r\n<p>Rut</p>\r\n",
    "PostedDate": "2011-03-25T13:47:04.85-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "586847",
    "ThreadId": "251268",
    "Html": "<p>No, and maybe.</p>\r\n<p>DotNetZip does entry encryption, which means that the file data for each entry is encrypted, according to the zip spec. Using this method of zip encryption means that people can view the \"table of contents\" for a zip file (also known as the \"central directory\" in zip speak) without entering a password.</p>\r\n<p>There is a way to do \"central directory encryption\" described in the zip spec, but I haven't implemented that in DotNetZip.&nbsp;</p>\r\n<p>Some possible ways&nbsp;around what you describe as the problem:</p>\r\n<ol>\r\n<li>you say it seems silly to enter&nbsp;a password for each file. I'm not sure what you are using to unpack, but it seems like it's your own custom app.&nbsp; in your application, cache the password for a given entry, then try it as the password for the next encrypted entry.&nbsp;&nbsp; only prompt for a new password if the cached one fails. In the common case where the same password has been used for all entries in a zip, the user needs enter the password just once. </li>\r\n<li>Zip the zip.&nbsp; If you want to keep the contents of a zip private, encrypt it inside another zip file.&nbsp; The outer zip protects the inner zip.&nbsp; The user needs to enter a password to unpack the inner zip, and only then can view the \"table of contents\" of said inner zip.</li>\r\n</ol>\r\n<p>&nbsp;</p>",
    "PostedDate": "2011-03-26T00:40:15.55-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "586872",
    "ThreadId": "251268",
    "Html": "<p>Thanks. I think I tried zipping the zip file but it didn't seem to work. I'll look at it again.&nbsp; The end user would normally use winzip or winrar to open the zip file, not my application (which simply copies files and zips them). When opening in winrar, it asks for a password for each file.</p>",
    "PostedDate": "2011-03-26T04:51:25.163-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "587527",
    "ThreadId": "251268",
    "Html": "<p>I have two questions now. I'm trying to save a zip file within a zipfile and password protect it.&nbsp; When I open the outer zip with winrar and double-click on the inner zip, it prompts me for a password. If I enter nothing and press cancel it continues to open the inner zipfile. So it doesn't appear the password is required to open the inner zip.&nbsp; See code below.</p>\n<p>&nbsp;</p>\n<p>Also, is there a way to create a zip within a zip (with the inside zip password protected) and then unzip the outside zipfile so you are left with only the password protected zipfile?</p>\n<p>I've been trying to accomplish this but I'm having no luck.</p>\n<p>&nbsp;</p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim tmpName As String<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim tmpZip As New ZipFile<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim zip As New ZipFile<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim path As String<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'Get the real filename and add TMP to create the inner zipfile<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tmpName = IO.Path.GetFileName(Me.ZipFileName)<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; path = IO.Path.GetPathRoot(Me.ZipFileName)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tmpName = \"TMP\" &amp; tmpName</p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'Add the list of file paths/names to inner zipfile.<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For Each s As String In lstFilesToZip<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tmpZip.AddItem(s)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next</p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'Save inner zipfile<br />&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tmpZip.Save(path &amp; \"\\\" &amp; tmpName)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tmpZip = Nothing</p>\n<p>&nbsp;</p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'create outer zipfile and add inner zipfile with password.<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; zip.Password = ZipPassword<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; zip.AddFile(path &amp; \"\\\" &amp; tmpName)</p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'Save as real filename.<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; zip.Save(Me.ZipFileName)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; zip = Nothing</p>\n<p>&nbsp;</p>\n<p>Thanks,</p>\n<p>Rut</p>",
    "PostedDate": "2011-03-28T05:34:34.397-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "588972",
    "ThreadId": "251268",
    "Html": "<p>This code works for me</p>\r\n<div style=\"color: black; background-color: white;\">\r\n<pre>        <span style=\"color: blue;\">Dim</span> path <span style=\"color: blue;\">As</span> <span style=\"color: blue;\">String </span>= IO.Path.GetPathRoot(<span style=\"color: blue;\">Me</span>.ZipFileName)\r\n        System.Console.WriteLine(<span style=\"color: #a31515;\">\"Path:{0}\"</span>, path)\r\n\r\n        <span style=\"color: green;\">'Get the real filename and add TMP to create the inner zipfile</span>\r\n        <span style=\"color: blue;\">Dim</span> baseName <span style=\"color: blue;\">As</span> <span style=\"color: blue;\">String</span> = IO.Path.GetFileNameWithoutExtension(<span style=\"color: blue;\">Me</span>.ZipFileName)\r\n        <span style=\"color: blue;\">Dim</span> extension <span style=\"color: blue;\">As</span> <span style=\"color: blue;\">String</span> = IO.Path.GetExtension(<span style=\"color: blue;\">Me</span>.ZipFileName)\r\n        <span style=\"color: blue;\">Dim</span> innerZipName <span style=\"color: blue;\">As</span> <span style=\"color: blue;\">String</span> = baseName &amp; <span style=\"color: #a31515;\">\"-inner\"</span> &amp; extension\r\n        innerZipName = IO.Path.Combine(path, innerZipName)\r\n\r\n        System.Console.WriteLine(<span style=\"color: #a31515;\">\"innerZipName = {0}\"</span>, innerZipName)\r\n        DeleteIfPresent(innerZipName)\r\n\r\n        <span style=\"color: blue;\">Using</span> innerZip = <span style=\"color: blue;\">New</span> ZipFile\r\n\r\n            <span style=\"color: green;\">'Add the list of file paths/names to inner zipfile.</span>\r\n            <span style=\"color: blue;\">For</span> <span style=\"color: blue;\">Each</span> s <span style=\"color: blue;\">As</span> <span style=\"color: blue;\">String</span> <span style=\"color: blue;\">In</span> lstFilesToZip\r\n                innerZip.AddItem(s)\r\n            <span style=\"color: blue;\">Next</span>\r\n\r\n            <span style=\"color: green;\">'Save inner zipfile - no password protection needed</span>\r\n            innerZip.Save(innerZipName)\r\n        <span style=\"color: blue;\">End</span> <span style=\"color: blue;\">Using</span>\r\n\r\n\r\n        DeleteIfPresent(<span style=\"color: blue;\">Me</span>.ZipFileName)\r\n        <span style=\"color: blue;\">Using</span>  outerZip = <span style=\"color: blue;\">New</span> ZipFile\r\n            <span style=\"color: green;\">'create outer zipfile and add inner zipfile with password.</span>\r\n            outerZip.Password = <span style=\"color: blue;\">Me</span>.ZipPassword\r\n            <span style=\"color: blue;\">Dim</span> e <span style=\"color: blue;\">As</span> ZipEntry = outerZip.AddFile(innerZipName)\r\n            <span style=\"color: green;\">'Save as real filename.</span>\r\n            outerZip.Save(<span style=\"color: blue;\">Me</span>.ZipFileName)\r\n        <span style=\"color: blue;\">End</span> <span style=\"color: blue;\">Using</span>\r\n\r\n        <span style=\"color: green;\">'Remove the \"temporary\" inner zip file from the filesystem<br />        </span>IO.File.Delete(innerZipName)\r\n\r\n</pre>\r\n</div>\r\n<p>First thing - I recommend that you always employ a Using clause with the ZipFile type.&nbsp; Every example that I produce in the docucmentation and on the forums shows this.&nbsp; Do it, to avoid problems.&nbsp; Also, doing it this way avoids the need to set your variables equal to Nothing when finished.</p>\r\n<p>Ok - on to the code.&nbsp; It produces a single zip file - that zipfile itself contains a single (nested) zipfile, which contains the entries from lstFileNames. The inner zip can be extracted only with a password. Once the inner is extracted, then you have a zipfile, which can be opened and viewed freely.</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2011-03-30T11:03:09.217-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "588976",
    "ThreadId": "251268",
    "Html": "\r\n<div>\r\n<p><span style=\"font-size:11.0pt; font-family:\">Thanks but did you try opening the file (outer zip) with Winrar? When I double-click on the zip file I see the inner zipfile. When I double-click on it I get a password prompt. If I enter nothing and click ok\r\n it opens up the inner zipfile and I can see all my files (and open them) without ever entering a password.</span></p>\r\n<p><span style=\"font-size:11.0pt; font-family:\"></span></p>\r\n<p><span style=\"font-size:11.0pt; font-family:\">Rut</span></p>\r\n<p><span style=\"font-size:11.0pt; font-family:\"></span></p>\r\n<div>\r\n<div style=\"border:none; border-top:solid #B5C4DF 1.0pt; padding:3.0pt 0in 0in 0in\">\r\n<p><b><span style=\"font-size:10.0pt; font-family:\">From:</span></b><span style=\"font-size:10.0pt; font-family:\"> Cheeso [email removed]\r\n<br>\r\n<b>Sent:</b> Wednesday, March 30, 2011 2:03 PM<br>\r\n<b>To:</b> jrutledge@triad.rr.com<br>\r\n<b>Subject:</b> Re: dotnetzip password question [DotNetZip:251268]</span></p>\r\n</div>\r\n</div>\r\n<p></p>\r\n<p><span style=\"font-size:9.0pt; font-family:\">From: Cheeso</span></p>\r\n<div id=\"x_x_ThreadNotificationPostBody\" style=\"margin-bottom:24.0pt\">\r\n<p><span style=\"font-size:9.0pt; font-family:\">This code works for me</span></p>\r\n<div>\r\n<pre style=\"background:white\"><span style=\"font-size:11.5pt; color:black\">        </span><span style=\"font-size:11.5pt; color:blue\">Dim</span><span style=\"font-size:11.5pt; color:black\"> path </span><span style=\"font-size:11.5pt; color:blue\">As</span><span style=\"font-size:11.5pt; color:black\"> </span><span style=\"font-size:11.5pt; color:blue\">String </span><span style=\"font-size:11.5pt; color:black\">= IO.Path.GetPathRoot(</span><span style=\"font-size:11.5pt; color:blue\">Me</span><span style=\"font-size:11.5pt; color:black\">.ZipFileName)</span></pre>\r\n<pre style=\"background:white\"><span style=\"font-size:11.5pt; color:black\">        System.Console.WriteLine(</span><span style=\"font-size:11.5pt; color:#A31515\">&quot;Path:{0}&quot;</span><span style=\"font-size:11.5pt; color:black\">, path)</span></pre>\r\n<pre style=\"background:white\"><span style=\"font-size:11.5pt; color:black\"> </span></pre>\r\n<pre style=\"background:white\"><span style=\"font-size:11.5pt; color:black\">        </span><span style=\"font-size:11.5pt; color:green\">'Get the real filename and add TMP to create the inner zipfile</span><span style=\"font-size:11.5pt; color:black\"></span></pre>\r\n<pre style=\"background:white\"><span style=\"font-size:11.5pt; color:black\">        </span><span style=\"font-size:11.5pt; color:blue\">Dim</span><span style=\"font-size:11.5pt; color:black\"> baseName </span><span style=\"font-size:11.5pt; color:blue\">As</span><span style=\"font-size:11.5pt; color:black\"> </span><span style=\"font-size:11.5pt; color:blue\">String</span><span style=\"font-size:11.5pt; color:black\"> = IO.Path.GetFileNameWithoutExtension(</span><span style=\"font-size:11.5pt; color:blue\">Me</span><span style=\"font-size:11.5pt; color:black\">.ZipFileName)</span></pre>\r\n<pre style=\"background:white\"><span style=\"font-size:11.5pt; color:black\">        </span><span style=\"font-size:11.5pt; color:blue\">Dim</span><span style=\"font-size:11.5pt; color:black\"> extension </span><span style=\"font-size:11.5pt; color:blue\">As</span><span style=\"font-size:11.5pt; color:black\"> </span><span style=\"font-size:11.5pt; color:blue\">String</span><span style=\"font-size:11.5pt; color:black\"> = IO.Path.GetExtension(</span><span style=\"font-size:11.5pt; color:blue\">Me</span><span style=\"font-size:11.5pt; color:black\">.ZipFileName)</span></pre>\r\n<pre style=\"background:white\"><span style=\"font-size:11.5pt; color:black\">        </span><span style=\"font-size:11.5pt; color:blue\">Dim</span><span style=\"font-size:11.5pt; color:black\"> innerZipName </span><span style=\"font-size:11.5pt; color:blue\">As</span><span style=\"font-size:11.5pt; color:black\"> </span><span style=\"font-size:11.5pt; color:blue\">String</span><span style=\"font-size:11.5pt; color:black\"> = baseName & </span><span style=\"font-size:11.5pt; color:#A31515\">&quot;-inner&quot;</span><span style=\"font-size:11.5pt; color:black\"> & extension</span></pre>\r\n<pre style=\"background:white\"><span style=\"font-size:11.5pt; color:black\">        innerZipName = IO.Path.Combine(path, innerZipName)</span></pre>\r\n<pre style=\"background:white\"><span style=\"font-size:11.5pt; color:black\"> </span></pre>\r\n<pre style=\"background:white\"><span style=\"font-size:11.5pt; color:black\">        System.Console.WriteLine(</span><span style=\"font-size:11.5pt; color:#A31515\">&quot;innerZipName = {0}&quot;</span><span style=\"font-size:11.5pt; color:black\">, innerZipName)</span></pre>\r\n<pre style=\"background:white\"><span style=\"font-size:11.5pt; color:black\">        DeleteIfPresent(innerZipName)</span></pre>\r\n<pre style=\"background:white\"><span style=\"font-size:11.5pt; color:black\"> </span></pre>\r\n<pre style=\"background:white\"><span style=\"font-size:11.5pt; color:black\">        </span><span style=\"font-size:11.5pt; color:blue\">Using</span><span style=\"font-size:11.5pt; color:black\"> innerZip = </span><span style=\"font-size:11.5pt; color:blue\">New</span><span style=\"font-size:11.5pt; color:black\"> ZipFile</span></pre>\r\n<pre style=\"background:white\"><span style=\"font-size:11.5pt; color:black\"> </span></pre>\r\n<pre style=\"background:white\"><span style=\"font-size:11.5pt; color:black\">            </span><span style=\"font-size:11.5pt; color:green\">'Add the list of file paths/names to inner zipfile.</span><span style=\"font-size:11.5pt; color:black\"></span></pre>\r\n<pre style=\"background:white\"><span style=\"font-size:11.5pt; color:black\">            </span><span style=\"font-size:11.5pt; color:blue\">For</span><span style=\"font-size:11.5pt; color:black\"> </span><span style=\"font-size:11.5pt; color:blue\">Each</span><span style=\"font-size:11.5pt; color:black\"> s </span><span style=\"font-size:11.5pt; color:blue\">As</span><span style=\"font-size:11.5pt; color:black\"> </span><span style=\"font-size:11.5pt; color:blue\">String</span><span style=\"font-size:11.5pt; color:black\"> </span><span style=\"font-size:11.5pt; color:blue\">In</span><span style=\"font-size:11.5pt; color:black\"> lstFilesToZip</span></pre>\r\n<pre style=\"background:white\"><span style=\"font-size:11.5pt; color:black\">                innerZip.AddItem(s)</span></pre>\r\n<pre style=\"background:white\"><span style=\"font-size:11.5pt; color:black\">            </span><span style=\"font-size:11.5pt; color:blue\">Next</span><span style=\"font-size:11.5pt; color:black\"></span></pre>\r\n<pre style=\"background:white\"><span style=\"font-size:11.5pt; color:black\"> </span></pre>\r\n<pre style=\"background:white\"><span style=\"font-size:11.5pt; color:black\">            </span><span style=\"font-size:11.5pt; color:green\">'Save inner zipfile - no password protection needed</span><span style=\"font-size:11.5pt; color:black\"></span></pre>\r\n<pre style=\"background:white\"><span style=\"font-size:11.5pt; color:black\">            innerZip.Save(innerZipName)</span></pre>\r\n<pre style=\"background:white\"><span style=\"font-size:11.5pt; color:black\">        </span><span style=\"font-size:11.5pt; color:blue\">End</span><span style=\"font-size:11.5pt; color:black\"> </span><span style=\"font-size:11.5pt; color:blue\">Using</span><span style=\"font-size:11.5pt; color:black\"></span></pre>\r\n<pre style=\"background:white\"><span style=\"font-size:11.5pt; color:black\"> </span></pre>\r\n<pre style=\"background:white\"><span style=\"font-size:11.5pt; color:black\"> </span></pre>\r\n<pre style=\"background:white\"><span style=\"font-size:11.5pt; color:black\">        DeleteIfPresent(</span><span style=\"font-size:11.5pt; color:blue\">Me</span><span style=\"font-size:11.5pt; color:black\">.ZipFileName)</span></pre>\r\n<pre style=\"background:white\"><span style=\"font-size:11.5pt; color:black\">        </span><span style=\"font-size:11.5pt; color:blue\">Using</span><span style=\"font-size:11.5pt; color:black\">  outerZip = </span><span style=\"font-size:11.5pt; color:blue\">New</span><span style=\"font-size:11.5pt; color:black\"> ZipFile</span></pre>\r\n<pre style=\"background:white\"><span style=\"font-size:11.5pt; color:black\">            </span><span style=\"font-size:11.5pt; color:green\">'create outer zipfile and add inner zipfile with password.</span><span style=\"font-size:11.5pt; color:black\"></span></pre>\r\n<pre style=\"background:white\"><span style=\"font-size:11.5pt; color:black\">            outerZip.Password = </span><span style=\"font-size:11.5pt; color:blue\">Me</span><span style=\"font-size:11.5pt; color:black\">.ZipPassword</span></pre>\r\n<pre style=\"background:white\"><span style=\"font-size:11.5pt; color:black\">            </span><span style=\"font-size:11.5pt; color:blue\">Dim</span><span style=\"font-size:11.5pt; color:black\"> e </span><span style=\"font-size:11.5pt; color:blue\">As</span><span style=\"font-size:11.5pt; color:black\"> ZipEntry = outerZip.AddFile(innerZipName)</span></pre>\r\n<pre style=\"background:white\"><span style=\"font-size:11.5pt; color:black\">            </span><span style=\"font-size:11.5pt; color:green\">'Save as real filename.</span><span style=\"font-size:11.5pt; color:black\"></span></pre>\r\n<pre style=\"background:white\"><span style=\"font-size:11.5pt; color:black\">            outerZip.Save(</span><span style=\"font-size:11.5pt; color:blue\">Me</span><span style=\"font-size:11.5pt; color:black\">.ZipFileName)</span></pre>\r\n<pre style=\"background:white\"><span style=\"font-size:11.5pt; color:black\">        </span><span style=\"font-size:11.5pt; color:blue\">End</span><span style=\"font-size:11.5pt; color:black\"> </span><span style=\"font-size:11.5pt; color:blue\">Using</span><span style=\"font-size:11.5pt; color:black\"></span></pre>\r\n<pre style=\"background:white\"><span style=\"font-size:11.5pt; color:black\"> </span></pre>\r\n<pre style=\"background:white\"><span style=\"font-size:11.5pt; color:black\">        </span><span style=\"font-size:11.5pt; color:green\">'Remove the &quot;temporary&quot; inner zip file from the filesystem<br>        </span><span style=\"font-size:11.5pt; color:black\">IO.File.Delete(innerZipName)</span></pre>\r\n<pre style=\"background:white\"><span style=\"font-size:11.5pt; color:black\"> </span></pre>\r\n</div>\r\n<p><span style=\"font-size:9.0pt; font-family:\">First thing - I recommend that you always employ a Using clause with the ZipFile type. Every example that I produce in the docucmentation and on the forums shows this. Do it, to avoid problems. Also, doing it this\r\n way avoids the need to set your variables equal to Nothing when finished.</span></p>\r\n<p><span style=\"font-size:9.0pt; font-family:\">Ok - on to the code. It produces a single zip file - that zipfile itself contains a single (nested) zipfile, which contains the entries from lstFileNames. The inner zip can be extracted only with a password. Once\r\n the inner is extracted, then you have a zipfile, which can be opened and viewed freely.</span></p>\r\n<p><span style=\"font-size:9.0pt; font-family:\"></span></p>\r\n</div>\r\n</div>\r\n",
    "PostedDate": "2011-03-30T11:08:21.51-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "589023",
    "ThreadId": "251268",
    "Html": "<p>Hmm, I don't have WinRar, so no, I haven't tried that. I tried Windows Explorer to open them, and in that case, I got prompted for the password when I tried extracting the inner zip.&nbsp; If I enter the password, then it extracts; if I don't enter the password, then it does not extract.&nbsp; Once extracted, the inner zip opens and I can view and extract those files just fine.</p>\n<p>I also tried the same thing in DotNetZip (using the graphical tool that is built on DotNetZip) and got essentially the same behavior.</p>\n<p>update: ok I just downloaded winRar 4.0, and ran it on a zipfile produced with the code that I showed above.&nbsp; It did exactly what I described for Windows Explorer and for the DotNetZip tool.</p>\n<p><img src=\"http://imgur.com/DVDB9.png\" alt=\"\" /></p>\n<p>If I press \"Cancel\" when prompted for the password, it extracts no files.&nbsp; If I click OK with a blank password, it gives me the dialog box shown above.&nbsp; This is with the latest WinRar.&nbsp;</p>\n<p>So, I think you must be doing something wrong. Or you're making a bad assumption, somewhere.</p>",
    "PostedDate": "2011-03-30T12:29:00.643-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]