aspose file tools*
The moose likes Java in General and the fly likes How to password protect a zip file? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to password protect a zip file?" Watch "How to password protect a zip file?" New topic
Author

How to password protect a zip file?

Andrew Carney
Ranch Hand

Joined: Oct 17, 2006
Posts: 96
Hello,

I am using java.util.zip.* pacake in order to zip some files.
My question is: Is it possible to password protect this zip using Java API?
If yes, a code example will be helpful. Thanks!
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18856
    
    8

No, it isn't.
Andrew Carney
Ranch Hand

Joined: Oct 17, 2006
Posts: 96
What about Password-Based Encoding with JCE from the java security package?
Can't that API be applied on the zip file?
[ October 31, 2007: Message edited by: Roy Cohen ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42583
    
  65
You can certainly use JCE to encrypt a ZIP file, but that will not result in a file WinZip can open. The java.util.zip package simply doesn't support passwords.


Ping & DNS - my free Android networking tools app
Andrew Carney
Ranch Hand

Joined: Oct 17, 2006
Posts: 96
And what if it wasn't a zip file but a word/excel/text file.
Any option that could be password protected using Java API?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18856
    
    8

"Password-protected" only means something for a file format if that file format provides a way to provide a password and prompt for it. So general questions like that are useless.

It's possible, for example, that iText provides a way to password-protect a PDF file. (If PDF even supports such a thing, which I don't know.) But you'd have to look in the iText documentation for that. And of course iText wouldn't be able to password-protect a MS word file (again, if such a thing is even possible).
[ October 31, 2007: Message edited by: Paul Clapham ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42583
    
  65
Paul is good at guessing

PDF, DOC and XLS all support password-protection, but like he said, that's something inherent in the format, not something that can be added via a Java API.

While it's possible to write a Java ZIP package that supports passwords like the ones WinZip/PKZIP use, I'm not aware that any of the existing ones do.

(Just for completeness sake - yes, iText can handle PDF passwords).
Andrew Carney
Ranch Hand

Joined: Oct 17, 2006
Posts: 96
Ok so I'll just have java run WinZip from command line to create a zip with password...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to password protect a zip file?