• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to password protect a zip file?

 
Andrew Carney
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, it isn't.
 
Andrew Carney
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Andrew Carney
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok so I'll just have java run WinZip from command line to create a zip with password...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic