开发者

How to secure information in Android

开发者 https://www.devze.com 2023-03-24 12:50 出处:网络
How can I keep secure data from crackers in an android application? I need to use 开发者_运维知识库some secret keys (as the application will work through a web service) so I need to know where it woul

How can I keep secure data from crackers in an android application? I need to use 开发者_运维知识库some secret keys (as the application will work through a web service) so I need to know where it would be recommended to keep this secret information and how?


You could use SharedPreferences which is not stored in an accessible file/folder. Click here for information on SharedPreferences and here for how to use it. This is an example:

// Get settings
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
// Get editor to be able to put settings
SharedPreferences.Editor editor = settings.edit()
// Put information with specified key
editor.putString("example_key", "example value");
// Commit changes
editor.commit();
// Gets value from setting with the specified key
String exampleString = settings.getString("example_key", null);


You can save them in a Preferences object and encrypt them with a hard-coded key, save them to the app's data folder and encrypt the whole file with a hard-coded key, or save them in a web location (which is probably the safest way to do it). You could also substitute a user-provided password for a hard-coded key, but that may be a nuisance depending on what the app does. If you're asking for a place that Android provides specifically for storing sensitive info, I don't believe any exists.

0

精彩评论

暂无评论...
验证码 换一张
取 消