2016-11-25 111 views
0

我看到一些问题,询问“如何存储敏感数据和React Native”(如thisthis),但所有这些情况都是在动态地(例如从服务器)采集一些敏感数据,然后使用AsyncStorage进行存储。 但是,如果您需要在代码中写入敏感的代码/密码,那么该怎么办?如何在React Native代码中存储敏感数据?

例如,我想实现此库:https://github.com/fullstackreact/react-native-oauth 正如您在第一个示例中所看到的,我必须在代码中编写秘密令牌。

在所有react-native项目目录中,我可以放置令牌然后在应用程序中获取文件吗? 操作应用程序中的安全令牌有多少安全性?

感谢

+0

Asyncstorage是permament存储,所以我不会保存重要的信息有即使在离开应用程序后,删除它们的控制。因此,您可以使用暂时存储值的Mobx或Redux来存储这些信息。 –

+0

@BurakKarasoy但是,使用redux/mobx绝不会以任何特殊方式获得这些信息。此外,信息不会持续存在,您仍然有设置这些值的挑战。 – martinarroyo

+0

看看这个问题:http://stackoverflow.com/questions/1934187/oauth-secrets-in-mobile-apps – martinarroyo

回答

1

如何存储敏感数据作出反应本机代码?

是有办法做到这一点,你可以使用react-native-keychain来存储敏感数据react-native

在iOS设备上使用它钥匙扣共享功能

对于Android的使用它:

  • API等级16-22使用Facebook隐藏
  • API等级23+使用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); 
    }); 
相关问题