我看到了几个问题"如何存储敏感数据和React Native" (例如this和this),但是,所有这些案例都在谈论动态地(例如从服务器)获取一些敏感数据,然后使用AsyncStorage
存储它。
但是,如果你需要在CODE中写一个敏感的TOKEN / PASSWORD呢?
例如,我想实现这个库:https://github.com/fullstackreact/react-native-oauth 正如您在第一个示例中所看到的,我必须在代码中写入秘密令牌。
在所有react-native项目目录中是否有一个文件,我可以放置我的令牌然后在应用程序中获取它? 在应用程序中操纵那些安全令牌有多安全?
由于
答案 0 :(得分:2)
如何在React Native代码中存储敏感数据?
是的,有办法实现这一点,您可以使用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);
});