ammarahm-ed / react-native-mmkv-storage

An ultra fast (0.0002s read/write), small & encrypted mobile key-value storage framework for React Native written in C++ using JSI
https://rnmmkv.now.sh
MIT License
1.56k stars 109 forks source link

Encrypted Storage Bugfixes #303

Closed georgeflug closed 11 months ago

georgeflug commented 1 year ago

This fixes a few issues I've seen in a production app with encrypted storage.

This moves the initWithEncryptionWithoutSecureStorage call higher up because the app was crashing when trying to access secure storage on an instance that did not use secure storage. It was going down the if (IDStore.exists(id)) path which ultimately tried to encrypt with a key stored in secure storage even though it was configured to not use secure storage. This fixes #265

This also moves the initWithEncryptionUsingNewKey call higher up because the app got into a bad state where the IDStore.exists(id) call was returning true but the mmkvJsiModule.getSecureKey call was returning nothing. I'm not sure how it got into the bad state but it may be related to the problem that was fixed by 0.8.0. If the secure key does not exist, it should use a new key instead of continually trying to use the nonexistent key.

vercel[bot] commented 1 year ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
rnmmkv ✅ Ready (Inspect) Visit Preview Jan 3, 2023 at 6:00PM (UTC)
ammarahm-ed commented 1 year ago

Hi, using a new key if the existing key did not exist means the data encrypted with older key will not exist anymore. It will be wiped and replaced with new data. I am not sure if it's a good solution yet to immediately create a new key & and a new storage instance.