• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to password protect a zip file?

 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, it isn't.
 
Andrew Carney
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok so I'll just have java run WinZip from command line to create a zip with password...
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic