I need to hide the password in the source, what are the possible methods to obfuscate the password in order to reduce the risk of decompilation?
e.g.
final String password = "secret";
I need to hide the password in the source, what are the possible methods to obfuscate the password in order to reduce the risk of decompilation?
e.g.
final String password = "secret";
Don't bother.
Your average user won't be able or willing to decompile class files anyway, and a motivated and skilled attacker won't be held back by obfuscation when the target is a single piece of data. All it takes is one such motivated and skilled attacker and the whole world knows the password.
If your security depends on obfuscating a password, you have already lost.
First, I wouldn't name my variable password
.
Second, I wouldn't keep it in raw format, but encode it.
Third, I'd use a char[]
instead of String
(because strings reside in the string pool).
Of course the best option would be to not keep it in the code at all.
Encrypt the password using an external method, a method that can be used decrypt within your code and store the password (encrypted) on your code