• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to create password protect text file using java ?

 
Saurabh Naik
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello..
In my application I want to make text i.e .txt file password protected using Java.. is it Possible ?
 
Rob Spoor
Sheriff
Pie
Posts: 20610
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simple .txt files have no nice features like formatting or password protection. You will need to wrap the file into a different format that does support password protection, and also use a program that understands it to read them again.

I've tried out AxCrypt once and it can do what you want. If you want to program this yourself, for the encryption you should check out CipherOutputStream for writing and CipherInputStream for reading.
 
Saurabh Naik
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
AxCrypt is fine but how can I do it Programatically ?

Even java.util.zip.ZipEntry class doent have setPassword method

I am generating some files programatically and I want to make those file password protected
 
Henry Wong
author
Marshal
Pie
Posts: 21420
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Did you look into the other two classes that Rob recommended?

Henry
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In this context, password == encryption key.
 
Saurabh Naik
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
did lot of search on it ...but didn't work

finally found the bug

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4347142
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why didn't you state up front that you were talking about ZIP files? Password protection is not a feature of the standard ZIP format, making it unlikely that the class libraries will ever have it.
 
Efrain Morales
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you could use SecureZIP CLI

You would be running an .exe or a bat file from your java progam... it's not elegant but it would do the trick...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic