• Post Reply Bookmark Topic Watch Topic
  • New Topic

Password protection in java.io.File

 
Dev Dilip
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
is there anyway to set a password for a file generated through java.
I mean if I create a file using - new File("c:\\abcd.xls");
Can a password be set to that file, so as to make it secure.

Thanks
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

To "set a password for a file" means to encrypt the content, somehow, such that it can only be opened with a matching decryption program using that same password. In the example you give, there is only one, possibly two options:

First, if Excel has a way to password-protect spreadsheets, then an API that works with spreadsheet files might be able to do this, so that Excel itself could decrypt the file. Apache's POI project is your best bet work working with Excel files using Java.

Second, if it doesn't, then the best you could do would be to use something like JCE, the Java Cryptography Extensions, the encrypt the file. In that case, you'd also need to write and make available a decryption program that could open the file for the user.

Google should quickly find Apache POI and JCE for you.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!