aspose file tools*
The moose likes I/O and Streams and the fly likes Can anyone help? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Can anyone help?" Watch "Can anyone help?" New topic
Author

Can anyone help?

Dave Donohoe
Ranch Hand

Joined: May 16, 2000
Posts: 73
Does anyone know of any way that get my Java App to compress & paswword enable an input file & then be able to read the contents using the password?
If it helps any, the file is XML.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
You mean like a password protected zip file? The classes to zip files are in java.util.zip.
Dave Donohoe
Ranch Hand

Joined: May 16, 2000
Posts: 73
Thanks, but I couldnot find anything about password protection in java.util.zip - I could read the files, but thy are files with no password assigned.
Basically I want my Java App to be able to read/write the files but if you go to the file from command prompt or Windows Explorer, then you cannot access the file without the password.
Is this any clearer?
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Gotcha. I did a quick search of the API and I too found nothing on this. I also searched in Sun's tutorials and found nothing. So here is my suggestion:
You could use java.util.zip to compress the file(s) and then you could encrypt the ZIP using one of several methods, depending on how serious you are about protecting your data and how much you want to spend on this. If you are cheap and not very paranoid, you could use Sun's reference implementation of the JCE (Java Cryptography Extention). If you are more paranoid or interested in spending some money on the project, you could use the JCE API with a third party cryptographic service provider.
There is a really cheezy solution that I would probably only use if this program were for inter-office use or something. That is, I would write a small class that performs a bitwise XOR on each byte of the file against some user-provided encryption key. For example, you could prompt the user to enter a password. Then you could do the XOR against that password for each byte. When you want to decrypt the file, you will have to perform the XOR with the same key. The encrypted file on the network would be useless to anyone that doesn't have you Encryption/Decryption class and the key for the file. Cheezy, I know, but I've done this before with C and had some success in an office environment at protecting things like performance reviews from the prying eyes of network admins and other privelaged peeping toms.
Dave Donohoe
Ranch Hand

Joined: May 16, 2000
Posts: 73
Thanks for your help - much appriciated.
I will try these methods & see which one suits me best,
Thanks again
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Can anyone help?