views:

297

answers:

1

I want to store some small but critical piece of information such as AES keys in my Android application. What would be the recommended way to do this? I do not want to hardcode keys as part of my application.

I look at KeyStore but it does not really solve my problem. It can store my keys given that I can provide a password. Then I need to find a secure place to store this password which is same as my original problem.

Is there a built in Android class to perform this task? Or should I look for third party libraries? Using NDK is also acceptable for me.

Update:

I was hoping to find an Android API for storage such that guarantees that only the application that stored some information can retrieve it back. Android OS could have enforced this based on signing signatures of the application. This way my application can generate a random key on first run and store it in secure storage for later use. Are there any API for this?

+1  A: 

Is there a built in Android class to perform this task?

Other than java.io.File, no.

Or should I look for third party libraries?

You can try, but I suspect most will look like the solution you already rejected. Most secure data stores involve passwords and assume the passwords are held elsewhere (e.g., in a user's head). For example, OI Safe has an Intent-based system of allowing applications to store stuff in the safe, but then the user is involved in unlocking the safe, IIRC.

CommonsWare
Thank you for the answer. It does not really solve my problem but it is good to know the limitations.
Szere Dyeri
@Szere Dyeri: "I was hoping to find an Android API for storage such that guarantees that only the application that stored some information can retrieve it back." -- there is no such API in Android, sorry.
CommonsWare
What do you mean there is no such API? This guarantee is the default behavior for all files the app stores on internal storage, since each application is given a unique user ID and the default mode of files an app creates is to be only readable/writeable by the creator's uid. The only except to this is (a) files placed on external storage, and (b) files created with the flag to make them world readable/writeable. The only way another application can run with your uid is if both (a) it is signed with your cert and (b) you both have the same android:sharedUserId.
hackbod
@hackbod: I was under the impression that the OP was seeking something that would survive a rooted device. Your solution, while entirely apropos otherwise, can be trivially defeated by rooting. However, a root-proof solution is definitely an assumption of mine, and I apologize to the OP if rooting is not a particular concern.
CommonsWare
Oh if the user has root, there is no data you can protect, period, end of story. You can try to make things more difficult, but actual protection is gone.
hackbod