0

I want to encrypt .jar file of my android application so that it can't be decoded by any one to view the source code. How can I achieve this?

AndyN
  • 1,742
  • 1
  • 15
  • 30
  • 5
    .jar files don't contain source code. They contain bytecode (which can be decompiled to a possible source code version). Assuming that's what you meant, consider this: If nobody can decrypt it and retrieve the bytecode, nobody can run it because that's a requirement for running it. –  Dec 26 '13 at 12:21
  • @delnan Though it contains bytecode there are several tools available which decodes bytecode and then the source code can be viewed – AndyN Dec 26 '13 at 12:26
  • I know. That's what my parenthesised remark refered to. So, did you consider the aforementioned problem? –  Dec 26 '13 at 12:28
  • @delnan yes thats what I mean to say. – AndyN Dec 26 '13 at 12:31
  • @N2P in general, if you are asking a question of tools, debugging, or implementation - its more appropriate on SO. If, however, the question is one that is more of design, patterns, and algorithms, it tends to be more appropriate on P.SE. Look at the [help/on-topic] of each site to see how this difference plays out. –  Dec 26 '13 at 15:10

2 Answers2

1

It will always be possible to decompile it.

You can only obfuscate your code to make it harder to understand for humans. If your project insists of more than a few classes the effort to understand it will be higher than any one is willing to invest.

One tool to achieve this, which also reduces the size of your class-files is
ProGuard: http://proguard.sourceforge.net/

But there are quite some similar tools out there.

MrSmith42
  • 9,961
  • 6
  • 38
  • 49
0

Firstly - you can exclude source code from jar files. It is not required at runtime. Class files are sufficient.

Encrypting will not help you, if you encrypt the files JVM will not be able to understand it.

As responded in the earlier answer, there will always be tools to decompile the byte codes, you can make it harder for the attacker to read so that it is not worth his time

Saran Makam
  • 126
  • 7
  • If it is in eclipse you can refer to this post. http://stackoverflow.com/questions/1489179/exclude-files-from-jar-or-war-in-eclipse if not how are you generating the jar file – Saran Makam Dec 27 '13 at 15:54