Kraishan
Kraishan

Reputation: 455

Hide a class in a .jar

Whenever I build my app all classes (logically) are visible in the .jar that comes out of it. Aswell as a class that holds information to my MYSQL server (for the app to connect to). But I dont want this information to be publicly visible!

How can I "hide" this code or "hide" the class?

Thanks!!

Upvotes: 2

Views: 757

Answers (1)

Esteban
Esteban

Reputation: 162

I think you mean you dont want someone to do reverse engineering with your .class inside your jar file. There are many decompilers that can do that. So you would need to Obfuscate your code with an obfuscator utility.

The process of obfuscation will convert bytecode into a logical equivalent version that is extremely difficult for decompilers to pick apart. Keep in mind that the decompilation process is extremely complicated and cannot be easily 'tweaked' to bypassed obfuscated code. Essentially the process is as follows:

  1. Compile Java source code using a regular compiler (ie. JDK)
  2. Run the obfuscator, passing in the compiled class file as a parameter. The result will be a different output file (perhaps with a different extension).

This file, when renamed as a .class file, will be functionally equivalent to the original bytecode. It will not affect performance because a virtual machine will still be able to interpret it.

Here is an article describing this process in more detail and introducing an early obfuscator, Crema:

http://www.javaworld.com/javaworld/javatips/jw-javatip22.html

Upvotes: 1

Related Questions