我想在我的 React Native 应用程序中保留用户的帐户凭据(即用户名和密码)。我应该使用AsyncStorage
吗?
换句话说,我想知道是否以及如何AsyncStorage
保护其内容。该文档是对沉默。
(我使用的是 RN v0.28)
AsyncStorage 安全吗?
没有AsyncStorage不安全,文档说:
AsyncStorage 是一个简单的、未加密的、异步的、持久的、键值存储系统,对应用程序是全局的。应该使用它代替 LocalStorage。
为了在本地存储安全信息,我真的建议您使用react-native-keychain和react-native
对于 iOS,它使用钥匙串共享功能
对于 Android,它使用:
这是一个简单的例子:
// Generic Password, service argument optional
Keychain
.setGenericPassword(username, password)
.then(function() {
console.log('Credentials saved successfully!');
});
// service argument optional
Keychain
.getGenericPassword()
.then(function(credentials) {
console.log('Credentials successfully loaded for user ' + credentials.username);
}).catch(function(error) {
console.log('Keychain couldn\'t be accessed! Maybe no value set?', error);
});
Run Code Online (Sandbox Code Playgroud)
否(至少在 iOS、RN v0.28 上)
AsyncStorage
将键值对作为纯文本 JSON 文件保存在 Documents 目录中。
如果你在iOS模拟器中运行它,你可以在以下位置找到它的内容:~/Library/Developer/CoreSimulator/Devices
从源代码中应该是显而易见的RCTAsyncLocalStorage
归档时间: |
|
查看次数: |
5151 次 |
最近记录: |