0

I'm looking for a way to generate a key on my app to connect to an API on my server, in the past users have decompiled the app and found the key, but with this method they can see how I generate the key but can't generate themselves the same key.

But still not sure if it is safe to use:

getClass().getHash();

Along with HTTPS it should be safe or am I missing something?

Shixons
  • 197
  • 3
  • 13

1 Answers1

0

No, it's not secure. If one can decompile your code, then he/she can always retrieve any stored or computed information, even if obfuscation takes place (it would be harder to spot it, but again one can dig more and find it).

Check this similar post suggesting Jasypt or some other practices to use/store passwords in your projects.

There is still no safe solution to store credentials, as a successful decompilation can always retrieve it. You could ask from a user to type a password on each run and temporarily keep it on memory, but it seems you are interested in keeping this information secret even from your legitimate users. Also, if you use a client cert, then one could copy/reuse it in another instance of your program.

One could even utilize embedded devices (eg smart cards), where you need advanced hardware intervention knowledge and tools to extract private keys/passwords. But again, you need a sophisticated protocol (eg combining MAC/IP), as an advanced hacker could perform a replay attack (copy/paste/share the encrypted output of the smartcard), so he can use it on another run instance.

That's why there is still software piracy out there! Find a working solution and you'll get rich!

Community
  • 1
  • 1
Kostas Kryptos
  • 4,081
  • 2
  • 23
  • 24
  • Of course I understand that but in this case, even if they see how I generate the password, they can't generate the same password, it should not matter if they decompile the app and see the code obfuscated or not. Am I missing something? – Shixons Feb 15 '16 at 03:33
  • How can you ensure that the password remains the same after each run? Default implementation of hashcode is JVM-specific (usually using internal address of objects as input) – Kostas Kryptos Feb 16 '16 at 07:54