<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Reading Password-Protected ZIP Files in Java</title>
	<atom:link href="http://blog.alutam.com/2009/10/31/reading-password-protected-zip-files-in-java/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.alutam.com/2009/10/31/reading-password-protected-zip-files-in-java/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
	<description>Sharing useful tips from my &#34;weekend projects&#34;</description>
	<lastBuildDate>Fri, 03 Feb 2012 22:03:56 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: hiblack</title>
		<link>http://blog.alutam.com/2009/10/31/reading-password-protected-zip-files-in-java/comment-page-1/#comment-1267</link>
		<dc:creator>hiblack</dc:creator>
		<pubDate>Fri, 06 Jan 2012 03:49:11 +0000</pubDate>
		<guid isPermaLink="false">http://blog.alutam.com/?p=102#comment-1267</guid>
		<description>Thank you, it&#039;s great  :-)</description>
		<content:encoded><![CDATA[<p>Thank you, it&#8217;s great  :-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martin</title>
		<link>http://blog.alutam.com/2009/10/31/reading-password-protected-zip-files-in-java/comment-page-1/#comment-1265</link>
		<dc:creator>Martin</dc:creator>
		<pubDate>Thu, 01 Dec 2011 04:02:30 +0000</pubDate>
		<guid isPermaLink="false">http://blog.alutam.com/?p=102#comment-1265</guid>
		<description>You can use it in any way you want. If you are re-publishing the source code, referring back to this blog in a javadoc comment would be nice.</description>
		<content:encoded><![CDATA[<p>You can use it in any way you want. If you are re-publishing the source code, referring back to this blog in a javadoc comment would be nice.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris</title>
		<link>http://blog.alutam.com/2009/10/31/reading-password-protected-zip-files-in-java/comment-page-1/#comment-1264</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Tue, 29 Nov 2011 15:09:54 +0000</pubDate>
		<guid isPermaLink="false">http://blog.alutam.com/?p=102#comment-1264</guid>
		<description>Hi Martin!

Thank you very much for your interesting blog!

We think about integrating your source code posted inside this blog entry &quot;Reading Password-Protected ZIP Files in Java&quot; into one of our applications intended to be finally used for production scenarios. Could you please let us know if you have any concerns regarding this approach? Please let us know if there are terms of a license or any other restrictions we might be aware of?

Your help is much appreciated!

Kind Regards,

Chris</description>
		<content:encoded><![CDATA[<p>Hi Martin!</p>
<p>Thank you very much for your interesting blog!</p>
<p>We think about integrating your source code posted inside this blog entry &#8220;Reading Password-Protected ZIP Files in Java&#8221; into one of our applications intended to be finally used for production scenarios. Could you please let us know if you have any concerns regarding this approach? Please let us know if there are terms of a license or any other restrictions we might be aware of?</p>
<p>Your help is much appreciated!</p>
<p>Kind Regards,</p>
<p>Chris</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martin</title>
		<link>http://blog.alutam.com/2009/10/31/reading-password-protected-zip-files-in-java/comment-page-1/#comment-1263</link>
		<dc:creator>Martin</dc:creator>
		<pubDate>Wed, 23 Nov 2011 18:59:05 +0000</pubDate>
		<guid isPermaLink="false">http://blog.alutam.com/?p=102#comment-1263</guid>
		<description>Well, I have been thinking for some time I&#039;d create an open source project for this and add the output stream as well - as I do see this simple post on my blog is getting lots of hits - so seems like it is quite useful. The problem with the output stream is that I won&#039;t be able to do it in a really streaming way because of the way how Java Zip output stream encodes the file - will have to read significant portion of the zip content into memory - so you will have to make sure your zip file is of a reasonable size or that you allocate enough heap. Will see if I get some time over the weekend... :)</description>
		<content:encoded><![CDATA[<p>Well, I have been thinking for some time I&#8217;d create an open source project for this and add the output stream as well &#8211; as I do see this simple post on my blog is getting lots of hits &#8211; so seems like it is quite useful. The problem with the output stream is that I won&#8217;t be able to do it in a really streaming way because of the way how Java Zip output stream encodes the file &#8211; will have to read significant portion of the zip content into memory &#8211; so you will have to make sure your zip file is of a reasonable size or that you allocate enough heap. Will see if I get some time over the weekend&#8230; :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: faheem</title>
		<link>http://blog.alutam.com/2009/10/31/reading-password-protected-zip-files-in-java/comment-page-1/#comment-1262</link>
		<dc:creator>faheem</dc:creator>
		<pubDate>Wed, 23 Nov 2011 15:06:07 +0000</pubDate>
		<guid isPermaLink="false">http://blog.alutam.com/?p=102#comment-1262</guid>
		<description>Hi Martin

Congratulations! your program has become a defacto standard to decrypt password-protected zip files.

But my counterparts are expecting me now to send them PKWare encrypted zip files, after an extensive search I could find java programs which uses AES encryption but not PKWare.

I am in gr8 need of  ZipEncryptOutputStream :(

Any help ??</description>
		<content:encoded><![CDATA[<p>Hi Martin</p>
<p>Congratulations! your program has become a defacto standard to decrypt password-protected zip files.</p>
<p>But my counterparts are expecting me now to send them PKWare encrypted zip files, after an extensive search I could find java programs which uses AES encryption but not PKWare.</p>
<p>I am in gr8 need of  ZipEncryptOutputStream :(</p>
<p>Any help ??</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dennis</title>
		<link>http://blog.alutam.com/2009/10/31/reading-password-protected-zip-files-in-java/comment-page-1/#comment-1004</link>
		<dc:creator>Dennis</dc:creator>
		<pubDate>Thu, 06 Oct 2011 16:46:45 +0000</pubDate>
		<guid isPermaLink="false">http://blog.alutam.com/?p=102#comment-1004</guid>
		<description>Hi everyone I implemented that in c but I think there is a problem with password verification.
If I&#039;m not mistaken based on pkware we only use 1 byte to check the crc. So we decrypt the file header that is 12 bytes and take it&#039;s last byte and compare it with the crc value that we got from the CRC32 from Local file header so we have 1 byte that can get 255 values comparing with a random value that we got after decrypting the file header that other byte can also take 255 values. 
But the passwords that we can use are infinite so there should be many different passwords that might return the same crc value so that means that i might use a wrong password and that crc check will return that thee pass is correct! So it can&#039;t be only that 1 byte check it should be something more.... anyone has an idea how exactly it verify the password?</description>
		<content:encoded><![CDATA[<p>Hi everyone I implemented that in c but I think there is a problem with password verification.<br />
If I&#8217;m not mistaken based on pkware we only use 1 byte to check the crc. So we decrypt the file header that is 12 bytes and take it&#8217;s last byte and compare it with the crc value that we got from the CRC32 from Local file header so we have 1 byte that can get 255 values comparing with a random value that we got after decrypting the file header that other byte can also take 255 values.<br />
But the passwords that we can use are infinite so there should be many different passwords that might return the same crc value so that means that i might use a wrong password and that crc check will return that thee pass is correct! So it can&#8217;t be only that 1 byte check it should be something more&#8230;. anyone has an idea how exactly it verify the password?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: nolo</title>
		<link>http://blog.alutam.com/2009/10/31/reading-password-protected-zip-files-in-java/comment-page-1/#comment-772</link>
		<dc:creator>nolo</dc:creator>
		<pubDate>Wed, 28 Sep 2011 08:11:42 +0000</pubDate>
		<guid isPermaLink="false">http://blog.alutam.com/?p=102#comment-772</guid>
		<description>What does the second  limitation means , or how could I get the correct zip files ?</description>
		<content:encoded><![CDATA[<p>What does the second  limitation means , or how could I get the correct zip files ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stanislav Daskalov</title>
		<link>http://blog.alutam.com/2009/10/31/reading-password-protected-zip-files-in-java/comment-page-1/#comment-207</link>
		<dc:creator>Stanislav Daskalov</dc:creator>
		<pubDate>Thu, 01 Sep 2011 09:04:12 +0000</pubDate>
		<guid isPermaLink="false">http://blog.alutam.com/?p=102#comment-207</guid>
		<description>To be able to work with zero-length files just change the &quot;case HEADER&quot; block with:

case HEADER:
                    initKeys(password);
                    for (int i = 0; i = LFH_SIGNATURE.length) {
                                skipBytes = 2;
                                state = State.FLAGS;
                            }
                        }
                    	break;
                    }
                    // intentionally no break</description>
		<content:encoded><![CDATA[<p>To be able to work with zero-length files just change the &#8220;case HEADER&#8221; block with:</p>
<p>case HEADER:<br />
                    initKeys(password);<br />
                    for (int i = 0; i = LFH_SIGNATURE.length) {<br />
                                skipBytes = 2;<br />
                                state = State.FLAGS;<br />
                            }<br />
                        }<br />
                    	break;<br />
                    }<br />
                    // intentionally no break</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: PGiZ</title>
		<link>http://blog.alutam.com/2009/10/31/reading-password-protected-zip-files-in-java/comment-page-1/#comment-206</link>
		<dc:creator>PGiZ</dc:creator>
		<pubDate>Thu, 28 Jul 2011 15:30:54 +0000</pubDate>
		<guid isPermaLink="false">http://blog.alutam.com/?p=102#comment-206</guid>
		<description>Hi , Martin

I &#039;m try to write simple program for brute-force password in zip in Operating System Subject. First program for thread

I flow this appnote to decrypt header (12 first byte)

http://www.pkware.com/documents/casestudies/APPNOTE.TXT

Header decrypt with no problem. but I &#039;m not understand this message

&quot;After the header is decrypted,  the last 1 or 2 bytes in Buffer
should be the high-order word/byte of the CRC for the file being
decrypted, stored in Intel low-byte/high-byte order.  Versions of
PKZIP prior to 2.0 used a 2 byte CRC check; a 1 byte CRC check is
used on versions after 2.0.  This can be used to test if the password
supplied is correct or not.&quot;

I &#039;m try to put correct password. But last decrypted header value not match with
CRC Value (14 - 17 byte position). 

Here this code. Write in C++

[code]

#include 
#include 
#include 
#include 
#include 

#include &quot;pthread.h&quot;

unsigned int crc(unsigned int x , unsigned char b)
{
	x = x ^ (unsigned long)b;

	for(int i=0; i &gt; 1) ^ 0xEDB88320; 
		else
			x = (x &gt;&gt; 1);
	}
	return x;
}

int main()
{
	FILE *fp;
	char zip_location[] = &quot;D:\\Zip\\test_pass.zip&quot;;
	unsigned char password[] = &quot;1234&quot;;
	unsigned char header_buffer[12];
	unsigned char crc_file[25];
	unsigned int keys[3];
	unsigned int crc_decrypt;

	printf(&quot;\nFile = %s\n\n&quot;,zip_location);

	// First Init 96 Bit Internal State
	keys[0] = 0x12345678;
	keys[1] = 0x23456789;
	keys[2] = 0x34567890;

	// Step 1 - Initializing the encryption keys
	for(int i=0; i &gt; 24));
	}

	// Step 2 - Decrypting the encryption header
	fp = fopen (zip_location,&quot;r+b&quot;);
	if(fp == NULL) 
	{
		printf(&quot;Error! Can&#039;t open file\n&quot;);
	}
	else
	{
		fread(header_buffer,1,12,fp);

		// Jump to CRC32 Section
		fseek(fp,14,SEEK_SET);
		if(fread(crc_file, 1,4,fp))
		{
			printf(&quot;CRC From File = %X %X %X %X \n\n&quot;,crc_file[3],crc_file[2],crc_file[1],crc_file[0]);
		}
		fclose(fp);
	}

	for(int i=0; i&gt; 8);

		keys[0] = crc(keys[0],c);
		keys[1] = keys[1] + (keys[0] &amp; 0x000000FF);
		keys[1] = keys[1] * 134775813 + 1;
		keys[2] = crc(keys[2],keys[1] &gt;&gt; 24);

		header_buffer[i] = c;
	}

	for(int i=0; i&lt;12; i++)
		printf(&quot;Buffer[%d]\t= \t0x%X\n&quot;,i,header_buffer[i]);

	getch();

	return 0;
}

[/code]

My email : sum.developer [ a+t ] gmail.com</description>
		<content:encoded><![CDATA[<p>Hi , Martin</p>
<p>I &#8216;m try to write simple program for brute-force password in zip in Operating System Subject. First program for thread</p>
<p>I flow this appnote to decrypt header (12 first byte)</p>
<p><a href="http://www.pkware.com/documents/casestudies/APPNOTE.TXT" rel="nofollow">http://www.pkware.com/documents/casestudies/APPNOTE.TXT</a></p>
<p>Header decrypt with no problem. but I &#8216;m not understand this message</p>
<p>&#8220;After the header is decrypted,  the last 1 or 2 bytes in Buffer<br />
should be the high-order word/byte of the CRC for the file being<br />
decrypted, stored in Intel low-byte/high-byte order.  Versions of<br />
PKZIP prior to 2.0 used a 2 byte CRC check; a 1 byte CRC check is<br />
used on versions after 2.0.  This can be used to test if the password<br />
supplied is correct or not.&#8221;</p>
<p>I &#8216;m try to put correct password. But last decrypted header value not match with<br />
CRC Value (14 &#8211; 17 byte position). </p>
<p>Here this code. Write in C++</p>
<p>[code]</p>
<p>#include<br />
#include<br />
#include<br />
#include<br />
#include </p>
<p>#include "pthread.h"</p>
<p>unsigned int crc(unsigned int x , unsigned char b)<br />
{<br />
	x = x ^ (unsigned long)b;</p>
<p>	for(int i=0; i &gt; 1) ^ 0xEDB88320;<br />
		else<br />
			x = (x &gt;&gt; 1);<br />
	}<br />
	return x;<br />
}</p>
<p>int main()<br />
{<br />
	FILE *fp;<br />
	char zip_location[] = "D:\\Zip\\test_pass.zip";<br />
	unsigned char password[] = "1234";<br />
	unsigned char header_buffer[12];<br />
	unsigned char crc_file[25];<br />
	unsigned int keys[3];<br />
	unsigned int crc_decrypt;</p>
<p>	printf("\nFile = %s\n\n",zip_location);</p>
<p>	// First Init 96 Bit Internal State<br />
	keys[0] = 0x12345678;<br />
	keys[1] = 0x23456789;<br />
	keys[2] = 0x34567890;</p>
<p>	// Step 1 - Initializing the encryption keys<br />
	for(int i=0; i &gt; 24));<br />
	}</p>
<p>	// Step 2 - Decrypting the encryption header<br />
	fp = fopen (zip_location,"r+b");<br />
	if(fp == NULL)<br />
	{<br />
		printf("Error! Can't open file\n");<br />
	}<br />
	else<br />
	{<br />
		fread(header_buffer,1,12,fp);</p>
<p>		// Jump to CRC32 Section<br />
		fseek(fp,14,SEEK_SET);<br />
		if(fread(crc_file, 1,4,fp))<br />
		{<br />
			printf("CRC From File = %X %X %X %X \n\n",crc_file[3],crc_file[2],crc_file[1],crc_file[0]);<br />
		}<br />
		fclose(fp);<br />
	}</p>
<p>	for(int i=0; i&gt; 8);</p>
<p>		keys[0] = crc(keys[0],c);<br />
		keys[1] = keys[1] + (keys[0] &amp; 0x000000FF);<br />
		keys[1] = keys[1] * 134775813 + 1;<br />
		keys[2] = crc(keys[2],keys[1] &gt;&gt; 24);</p>
<p>		header_buffer[i] = c;<br />
	}</p>
<p>	for(int i=0; i&lt;12; i++)<br />
		printf(&quot;Buffer[%d]\t= \t0x%X\n&quot;,i,header_buffer[i]);</p>
<p>	getch();</p>
<p>	return 0;<br />
}</p>
<p>[/code]</p>
<p>My email : sum.developer [ a+t ] gmail.com</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: paul</title>
		<link>http://blog.alutam.com/2009/10/31/reading-password-protected-zip-files-in-java/comment-page-1/#comment-205</link>
		<dc:creator>paul</dc:creator>
		<pubDate>Tue, 21 Jun 2011 07:08:03 +0000</pubDate>
		<guid isPermaLink="false">http://blog.alutam.com/?p=102#comment-205</guid>
		<description>thanks for saving me the time!!</description>
		<content:encoded><![CDATA[<p>thanks for saving me the time!!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

