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

[Question] Migrating to an encypted instance #327

Closed Mookiies closed 1 year ago

Mookiies commented 1 year ago

I have an MMKV instance that's existed for awhile across several app releases, and now I want to start encrypting it.

Can I simply add withEncryption to the initialization?

Or is something slightly more complex where I must initialize a non-encrypted instance as it used to be, and then encrypt it via the encrypt method?

jobpaardekooper commented 1 year ago

The docs website has a page on how to go about this.

Mookiies commented 1 year ago

To answer this question for anyone else that comes upon it:

If an MMKV instance has been previously created, then adding withEncryption to the initializer will have no effect. To migrate a pre-existing instance to be encrypted it should be done via .encryption.encrypt() one instantialized.

To verify you can inspect the files MMKV stores: iOS: Data/Application/<application>/Library/mmkv Android: /data/data/<com.myapp>/files/mmkv/

Mookiies commented 1 year ago

I may submit a PR to clarify the docs as it is, imo, not clear that initialization options may not have any impact in this regard