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.58k stars 109 forks source link

[Bug] Custom Encryption Crashes if no Secure Storage #265

Open georgeflug opened 2 years ago

georgeflug commented 2 years ago

Describe the bug Loading an existing storage instance using a custom encryption key causes the app to crash if secure storage is not used.

To Reproduce Use the following code:

const myStorage = new MMKVLoader()
        .withInstanceID('myInstanceId')
        .withEncryption()
        .encryptWithCustomKey(`myEncryptionKey`, false)
        .initialize();

Expected behavior The storage is initialized the first time it is run. However, if you restart the app and initialize the storage again, the app exits immediately. I expect the storage to load without crashing.

Platform Information:

Additional context I did some troubleshooting and found that this line of code in initializer.js is the last line that runs before the crash: var key = mmkvJsiModule.getSecureKey(options.alias); (inside initWithEncryptionUsingOldKey). It seems it's trying to load the key from secure storage even though the secure storage boolean was set to false.