Question

I need to store a private string key inside of the app. Its value will never change and is set manually in code. I cannot obviously just store it as a String as reverse-engineering method would reveal it, even with obfuscation applied.

How do you suggest I protect this private key?

I though of saving it into a database, but a database can be pulled out of the phone as well.

PS. this key is a special parameter so an important method and it's crucial it stays unknown to anyone! It's not a decrypting key. This string will be used as a parameter to encryption method (md5 or similar) and then a result will be sent to our Internet service.

EDIT

Sorry, for making it so complicated. I thought I could get an answer with as few info as possible.

This app will allow users to send some text to an Internet service which then posts that text to a web site. We need to make sure that the text is sent via Android phone as any web robot script can mimic android phone and post a spam. As captcha-like methods are not welcome on mobile phones, there will be a secret key which will be put through md5 (with some other things) to generate a hash code. This hash will be sent to an Internet service. The Internet service will use the same key to get a md5 result and then compare it to see if the sender is a mobile phone or some robot.

This is really the max I am allowed to say. I hope it is enough.

Was it helpful?

Solution

I'd suggest that you rethink your security architecture. Anything shipped with the app is discoverable. (For instance, Android's license validation library is designed so that a public key is shipped with the app.)

One possibility is for the app to retrieve the key from a server (over a secure socket or https connection). This would obviously require that the app submit to the server some sort of identification/validation (probably based on user input).

If you're using the key for encryption, then take another look at how public key encryption is supposed to work. Your app should have the public key; the internet service can then decrypt with the matching private key.

OTHER TIPS

If you can settle with @Adam's comment, there is at least one solution I know of for persisting a String value on the phone in a... well... persistent manner, meaning that the value will survive a uninstall/re-install of your app (a factory reset would remove it though), yet remain "hidden" for the user (i.e. stored in system private storage, not on the SD-Card).

You can use the system settings content provider to store the value like so:

final String myKey = "verySecretKey";
final String myValue = "verySecretValue";
final boolean isSuccess = System.putString(getContentResolver(), myKey, myValue);

And to retrieve it you can do:

myValue = System.getString(getContentResolver(), myKey);

And yes, on a rooted phone a handy user might get hold of the persisted value, but in that case nothing is holy anymore and @Adam's comment will get valid: You shouldn't store the data on the device.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top