我想将敏感数据本地存储在 React Native 应用程序中。
数据是否仅适用于编写它的应用程序?
AsyncStorage 不适合存储敏感信息。您可能会发现这很有用:https ://github.com/oblador/react-native-keychain
它使用 facebook 隐藏/android 密钥库将加密数据存储到SharedPreferences
(Android) 和 iOS 上的钥匙串。(我与人合着了这个库)。请务必阅读整个自述文件以了解它提供的内容。
不,它不安全,因为它没有加密。我建议你使用 Expo 的 secureStore
如果您正在从 Expo 构建您的应用程序:
// in managed apps:
import { SecureStore } from 'expo';
如果您正在构建一个裸应用程序
// in bare apps:
import * as SecureStore from 'expo-secure-store';
在这里阅读更多:https ://docs.expo.io/versions/v32.0.0/sdk/securestore/
不,AsyncStorage 对敏感数据不安全。AsyncStorage 只是将数据保存到手机硬盘驱动器上的文档中,因此任何有权访问手机文件系统的人都可以读取该数据。当然,这对您来说是否有问题取决于您所说的“敏感数据”是什么意思。
至少在 iOS 上,由于 Apple 的沙盒策略,数据确实只对编写它的应用程序可用。这并不能阻止具有对文件系统的 root 访问权限的越狱 iPhone 获取他们想要的任何内容,因为 AsyncStorage 不会加密其任何数据。但一般来说,不要将敏感数据保存到 AsyncStorage,出于同样的原因,你不应该在 javascript 代码中对敏感数据进行硬编码,因为它很容易被反编译和读取。
For very sensitive app or user data, you could try something like https://github.com/oblador/react-native-keychain on iOS(uses iOS Keychain) or https://github.com/classapp/react-native-sensitive-info for both Android and iOS(uses Android Shared Preference and iOS Keychain).
Both of them come with very fluent API and straightforward way of linking with react-native link
and are a more secure way of preserving data you want to keep away from prying eyes.
不,它不安全。考虑使用像https://github.com/oblador/react-native-keychain这样的库来进行安全存储。
如果您使用 Expo,您可以使用Expo.SecureStore
它在设备本地加密和安全存储键值对。文档:https ://docs.expo.io/versions/latest/sdk/securestore
我在一个正在处理的项目中遇到了同样的问题,我们为 AsyncStorage 使用了一个自定义包装器,存储了一些数据,然后我们尝试检索相同的数据......这很容易。
我们通过使用带加密选项的Realm解决了这个问题,它比 AsyncStorage 更容易、更快和更好的解决方案。
我为 redux-persist 创建了一个安全存储模块,用于react-native-keychain
存储加密密钥并使用 CryptoJS 加密 AsyncStorage 中的静态 redux-store。您可以在以下位置找到该模块:
redux-persist-encrypted-async-storage
它的用法在链接的自述文件中进行了讨论。
来自 react-native 文档 - https://facebook.github.io/react-native/docs/asyncstorage.html
AsyncStorage 是一个简单的、未加密的、异步的、持久的、键值存储系统,对应用程序来说是全局的。
它不安全,因为它以未加密的形式在设备上存储键值对。
它使用 iOS 的钥匙串和 Android 的 KeyStore 来安全地存储数据。
如果你还在寻找这个。
尝试使用react-native-encrypted-storage
他们有一些加密。
react-native-encrypted-storage
就像异步存储一样简单