wood burning stoves 2.0*
The moose likes Java in General and the fly likes how to create password protect text file using java ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "how to create password protect text file using java ?" Watch "how to create password protect text file using java ?" New topic
Author

how to create password protect text file using java ?

Saurabh Naik
Ranch Hand

Joined: Apr 24, 2008
Posts: 87
Hello..
In my application I want to make text i.e .txt file password protected using Java.. is it Possible ?

SCJP 6 (88%), SCWCD 5 (78%), preparing for SCBCD
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Saurabh Naik
Ranch Hand

Joined: Apr 24, 2008
Posts: 87
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
Sheriff

Joined: Sep 28, 2004
Posts: 18876
    
  40



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

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42047
    
  64
In this context, password == encryption key.


Ping & DNS - my free Android networking tools app
Saurabh Naik
Ranch Hand

Joined: Apr 24, 2008
Posts: 87
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
Marshal

Joined: Mar 22, 2005
Posts: 42047
    
  64
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

Joined: Oct 14, 2009
Posts: 12
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...
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to create password protect text file using java ?