1

I am using mobx-persist library to persist data and I need to implement encryption since I am dealing with sensitive data. I know that AsyncStorage does not support encryption so my idea is using Realm as storage.

I am a beginner and I could not find anything to help me.

Have anyone tried before or have any example how to do this?

1 Answers1

0

Yes. You can create new class secureStorage, implement functions (getItem, setItem, removeItem) and pass it instead of async storage

I'm using react-native-sensitive-info, you can use whatever you want

import SInfo from 'react-native-sensitive-info';

export const setItem = (key: string, value: string) => {
  return new Promise(async (resolve, reject) => {
    try {
      await SInfo.setItem(key, value, options);
      resolve(null);
    } catch (e) {
      reject(e);
    }
  });
};

export const getItem = (key: string) => {
  return new Promise(async (resolve, reject) => {
    try {
      const result = await SInfo.getItem(key, options);
      resolve(result);
    } catch (e) {
      reject(e);
    }
  });
};

export function removeItem(key: string) {
  return new Promise(async (resolve, reject) => {
    try {
      await SInfo.deleteItem(key, options);
      resolve(null);
    } catch (err) {
      reject(err);
    }
  });
}

import * as SecureStorage from 'your-secure-storage';

const hydrate = create({
  storage: SecureStorage,
  jsonify: true,
});

Just replace SInfo with realm