如何在Android中保护信息



如何在android应用程序中保持安全数据?我需要使用一些秘密密钥(因为应用程序将通过web服务工作),所以我需要知道建议在哪里保存这些秘密信息以及如何保存这些秘密信息?

您可以使用SharedPreferences,它不存储在可访问的文件/文件夹中。点击这里了解SharedPreferences的信息,点击这里了解如何使用它。下面是一个示例:

// 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);

您可以将它们保存在Preferences对象中并使用硬编码密钥加密它们,将它们保存到应用程序的数据文件夹并使用硬编码密钥加密整个文件,或者将它们保存在web位置(这可能是最安全的方法)。你也可以用用户提供的密码代替硬编码的密钥,但这可能是一个麻烦,这取决于应用程序的功能。如果你要求Android提供一个专门存储敏感信息的地方,我认为不存在。

最新更新