Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hiding the source code in .jar files

One can easily extract the .jar file and see source code. I want to protect the source code from being seen. One possible answer is to password protect the file like we do it for zip files.

But, if the password is known, then the source code can be easily seen.

Are there any ways of hiding the source code and still have it be able to run? Something similar to what a .exe does in Windows. This should run in both windows as well as Linux environment.

like image 638
AGEM Avatar asked Jan 24 '13 01:01

AGEM


People also ask

Can you see the source code of a JAR file?

Jar files are archive files that contains of a lot of different java classes (files). You can use winzip/winrar to open the jar files and you can see those java classes in jar files. Typically you can use a Java decompiler to decompile the class file and look into the source code.

Can you encrypt a JAR file?

Jar files are not encrypted. They are . zip files. You can encrypt any file using Java if you want.


2 Answers

One can easily extract the .jar file and see the source code.

Strictly speaking, that is not true. Unless you've actually included the source code files in the JAR, someone cannot see the original source code. But they can (typically) decompile the ".class" files in your JAR file to Java source code that is functionally equivalent to your original source code.

As other answers have stated, you can make it harder for someone trying to reverse engineer your code; e.g. by using an obfuscator, or custom classloader that decrypts code that is stored in encrypted form in your JAR file. But nothing you can do is sufficient to prevent a determined hacker from defeating your measures. NOTHING.

The only practical way to protect your code against reverse engineering is to not release it. Or use software licensing or other legal means to achieve your ends.

like image 109
Stephen C Avatar answered Oct 06 '22 07:10

Stephen C


If you intend to simply discourage casual viewers then any of the many code obfuscation tools for Java would probably be of help. It will mess the bytecode enough to make your algorithms less obvious.

If, on the other hand, you need "absolute" protection, any encryption/obfuscation tool would be useless - if your computer can run it then a determined and knowledgeable attacker would be able to eventually figure out how your code works.

A couple of possible solutions:

  • Use a client/server architecture to run the proprietary parts on computers that you own, so that you do not have to include the more interesting part of your code in your client application. Naturally this solution is not always feasible for a variety of reasons.

  • Hire a couple of lawyers that specialize in Intellectual Property issues and patent your algorithms. In my opinion this is far batter an alternative than trying to force a technical solution on a non-technical problem...

like image 22
thkala Avatar answered Oct 06 '22 07:10

thkala