I want to save a static key and later I need to send it with as a header for https request, where I can put it securely in android?
Asked
Active
Viewed 34 times
1
-
Possible duplicate of [Best practice for storing and protecting private API keys in applications](https://stackoverflow.com/questions/14570989/best-practice-for-storing-and-protecting-private-api-keys-in-applications) – kelvin Aug 28 '19 at 12:19
-
Please check out this [QUESTION](https://stackoverflow.com/questions/14570989/best-practice-for-storing-and-protecting-private-api-keys-in-applications) – kelvin Aug 28 '19 at 12:21
1 Answers
0
You can user Shared Preference in Android. Read the documentation
val sharedPref = activity?.getPreferences(Context.MODE_PRIVATE) ?: return
with (sharedPref.edit()) {
putInt(getString(R.string.saved_high_score_key), newHighScore)
commit()
}
val defaultValue = resources.getInteger(R.integer.saved_high_score_default_key)
val highScore = sharedPref.getInt(getString(R.string.saved_high_score_key), defaultValue)

hfarhanahmed
- 184
- 1
- 7
-
friendly tip. link-only answers are not seen as answers and will typically be down-voted. consider giving a possible example of this or move this to a comment. Remember, links can change – a_local_nobody Aug 28 '19 at 06:37
-
@hfarhanahmed, I want to prevent a hacker from accessing any resources. – Sushant Chaturvedi Aug 28 '19 at 06:38
-
Then use google cloud project to store you Key and you have to make a call every time you call your own service. – hfarhanahmed Aug 28 '19 at 06:41
-
another way is you can right your own encryption and decryption and use the Shared preference. – hfarhanahmed Aug 28 '19 at 06:42
-
thanks for reply @hfarhanahmed, can I use aws KMS for that purpose because We are paying a huge amount to amazon. – Sushant Chaturvedi Aug 28 '19 at 06:46
-
Also I don't think if anyone re engineer your apk, they can't get your shared preference values. They can just get the code. get the key from api when the app starts and store it in shared preference and you are good – hfarhanahmed Aug 28 '19 at 06:51