问题描述
我想在我的 React Native 应用程序中保留用户的帐户凭据(即用户名和密码).我应该使用 AsyncStorage
吗?
换句话说,我想知道 AsyncStorage
是否以及如何保护其内容.docs 对此保持沉默.
(我使用的是 RN v0.28)
不,AsyncStorage 不安全,文档说:>
AsyncStorage 是一个简单的、未加密的、异步的、持久的、应用程序全局的键值存储系统.它应该被使用而不是 LocalStorage.
为了在本地存储安全信息,我强烈建议您使用 react-native-keychain 与 react-native
对于 iOS,它使用钥匙串共享功能
对于 Android,它使用:
- API 级别 16-22 使用 Facebook Conceal
- API 级别 23+ 使用 Android 密钥库
这是一个简单的例子:
//通用密码,服务参数可选钥匙链.setGenericPassword(用户名,密码).then(function() {console.log('凭据保存成功!');});//服务参数可选钥匙链.getGenericPassword().then(功能(凭据){console.log('Credentials 已成功加载用户 ' + credentials.username);}).catch(函数(错误){console.log('无法访问钥匙串!也许没有设置值?', error);});
I'd like to persist a user's account credentials (i.e. username and password) in my React Native app. Should I use AsyncStorage
?
In other words, I want to know if and how AsyncStorage
protects its contents. The docs are silent on that.
(I'm using RN v0.28)
No AsyncStorage is not secure, the docs says:
To store secure information on the native side, I really recommand you to use react-native-keychain with react-native
For iOS it use Keychain Sharing Capabilities
For Android it use:
- API level 16-22 use Facebook Conceal
- API level 23+ use Android Keystore
This is a simple example:
// 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);
});
这篇关于AsyncStorage 安全吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!