aspose file tools*
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: 19543
    
  16

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: 18117
    
  39



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: 39548
    
  27
In this context, password == encryption key.


Ping & DNS - updated with new look and Ping home screen widget
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: 39548
    
  27
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...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to create password protect text file using java ?
 
Similar Threads
String Encryption
How to password protect a zip file?
Open firefox window and redirect to a url
SHA1
how to set password to file with java program.?