File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes I/O and Streams and the fly likes and a password-protected zip file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark " and a password-protected zip file" Watch " and a password-protected zip file" New topic
Author and a password-protected zip file

Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
I'm trying to unzip files from within my Java program. Before I would try to just exec a process that would run pkunzip on my files, but I've been trying that on a Win2003 machine and would always get a strange error from Windows saying something about the environment not being set up (and yes, I was hardcoding the path to pkunzip). Anyway, for some strange reason I don't get that error anymore (and I didn't change anything on the server myself), but I had already started working on trying to use the package's classes to do this from pure Java code, so I'm now wondering if there's any way from within this Java package to unzip an encrypted (password-protected) zip file. Here's what I have so far:

[ August 24, 2004: Message edited by: Stephen Huey ]
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
Reference Website
How do I unzip a file that is password-protected?

This will hekp you....

Java Developer, Thailand
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
In the article provided by somkiat, it said that "The Java classes that read Zip files, e.g. ZipInputStream, do not support decrypting password-protected Zip files."

Your application must find a way to let the user specify the password to decrypt the zip file... You might need to find the documents or manuals that explain how to deal with encryption and decryption with a certain zip file...

Just my 2 cents..

Co-author of SCMAD Exam Guide, Author of JMADPlus
Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
It would be easy to obtain a password from the user, but in looking at the API, I'm not really sure how to use the password obtained. However, I'm guessing this means that all the bytes of the file need to be decrypted using that password string...

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

Moving to I/O and Streams since Zip operations are Input/Output and Stream operations.

GenRocket - Experts at Building Test Data
Martin Matula

Joined: Oct 31, 2009
Posts: 1
I wrote a simple class that can deal with a certain type of password-protected ZIPs in Java - here is more info:
Santosh Kumar Nayak
Ranch Hand

Joined: Aug 02, 2011
Posts: 141
Hi Team,

I have a zipped file and I want to add a password to the zipped file . Such that while unzipping the contents of the file it should ask for the password.

It is possible via Java API ?

I agree. Here's the link:
subject: and a password-protected zip file
It's not a secret anymore!