Save sensitive data in React Native

前端 未结 4 2113
日久生厌
日久生厌 2020-11-28 19:56

I am building a React Native application and I need to save some sensitive data like a token and a refresh token. The obvious solution is to save that information using Asyn

4条回答
  •  一向
    一向 (楼主)
    2020-11-28 20:25

    I really recommand you to use a library like react-native-keychain to store private data in react-native

    For Android API level:

    • 16-22 use Facebook Conceal
    • 23+ use Android Keystore

    You can use it like that:

    // 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);
      });
    

提交回复
热议问题