File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes unextratable jar file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "unextratable jar file" Watch "unextratable jar file" New topic

unextratable jar file

Mahendra Darwatkar

Joined: Apr 07, 2000
Posts: 20
Hi !!
How can i create a jar file which anybody can not able to extract.
Pl. reply me if any body is having solution for this.
Joel McNary

Joined: Aug 20, 2001
Posts: 1824

I know that some ZIP utilities can place a password on a ZIP file. However, I don't know if all ZIP decompressers respect this password. (A cursory glance through that and java.util.jar APIs turned up no reference to a password feature, so I assume that you could use jar.exe to extract a ZIP file that was password protected.)
What cames to mind would be to write a program that took a .jar file as an argument, read the bytes of the file and alter them using some algorithm that you wrote. You would then have to write a ClassLoader that could take one of these resulting files, reverse-engineer it to retreive the original .jar file, and then load the classes from that.
(Please note that this is just a theoretical solution--I take no blame for its impracticality )
[ May 24, 2003: Message edited by: Joel McNary ]

Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
It's not clear what your goal is here. A "jar file" is a format that, by design, anyone can extract from. If you change the file so it's no longer extractable, it's not really a jar file any more.
What's in the jar file? If you're using it for storing something other than .class files, then there are various ways you can encrypt the contents of a file. However if you're talking about the most common situation in which the jar file contains .class files which must be accessible and understandable by a JVM, then fundamentally it's not going to be possible to prevent people from accessing the original .class file. Evn if you bury it under one or more layers of encrytion and decryption - the JVM still needs to be able to receive an unecrypted version, or the class won't load. And it's always possible for someone to hack a JVM (source code for some versions is freely available) to copy the unencrypted version to a file. See this article for details.

"I'm not back." - Bill Harding, Twister
I agree. Here's the link:
subject: unextratable jar file
It's not a secret anymore!