Android - 存储 PIN/Password
Android - Storing a PIN/Password
心目中的应用程序有一个自定义键盘。 9 个按钮的 GridLayout,编号为 1-9。用户将按 4 个按钮,然后按 'enter' 来初始创建 PIN,然后再进行验证。
是否有可以存储(加密)和检索此 4 位 PIN 的内置方法?
大多数应用程序是如何做到这一点的?
作为一个简单的解决方案,散列此 PIN 并将其存储在首选项中是否足够?
您可以使用 this library 将 PIN 安全地存储在 SharedPreferences
中。
将此添加到您的 build.gradle
dependencies {
compile 'com.scottyab:secure-preferences-lib:0.1.4'
}
然后访问SecurePreferences
文件
SharedPreferences prefs = new SecurePreferences(context, null, "my_custom_prefs.xml");
从这里您可以像正常一样加载和保存到首选项
SharedPreferences.Editor editor = prefs.edit();
editor.putInt("userPin", pin).commit();
int pin = prefs.getInt("userPin", default);
图书馆免责声明:
By default it's not bullet proof security (in fact it's more like obfuscation of the preferences) but it's a quick win for incrementally making your android app more secure. For instance it'll stop users on rooted devices easily modifying your app's shared prefs. Recommend using the user password based prefs as introduced in v0.1.0.
心目中的应用程序有一个自定义键盘。 9 个按钮的 GridLayout,编号为 1-9。用户将按 4 个按钮,然后按 'enter' 来初始创建 PIN,然后再进行验证。
是否有可以存储(加密)和检索此 4 位 PIN 的内置方法?
大多数应用程序是如何做到这一点的?
作为一个简单的解决方案,散列此 PIN 并将其存储在首选项中是否足够?
您可以使用 this library 将 PIN 安全地存储在 SharedPreferences
中。
将此添加到您的 build.gradle
dependencies {
compile 'com.scottyab:secure-preferences-lib:0.1.4'
}
然后访问SecurePreferences
文件
SharedPreferences prefs = new SecurePreferences(context, null, "my_custom_prefs.xml");
从这里您可以像正常一样加载和保存到首选项
SharedPreferences.Editor editor = prefs.edit();
editor.putInt("userPin", pin).commit();
int pin = prefs.getInt("userPin", default);
图书馆免责声明:
By default it's not bullet proof security (in fact it's more like obfuscation of the preferences) but it's a quick win for incrementally making your android app more secure. For instance it'll stop users on rooted devices easily modifying your app's shared prefs. Recommend using the user password based prefs as introduced in v0.1.0.