[iOS] Add a new delegate RNCAsyncStorageCryptoDelegate to support encryption/decryption
See original GitHub issueMotivation
There are some cases where the data at rest must be encrypted (for e.g. to honor enterprise policies etc). Currently, if someone wants to store encrypted data using AsyncStorage they must encrypt it on the JS side before calling AsyncStorage. This is not the most ideal in terms of performance and this approach won’t be able to take advantage of the encryption libraries/capabilities already included in the native app.
Description
The proposal here is to introduce a new delegate RNCAsyncStorageCryptoDelegate
for performing crypto operations. This delegate is optional and will not be implemented by default but it gives developers the option to build encryption/decryption capabilities for AsyncStorage.
New feature implementation
The new delegate will have the following methods:
-(NSString *)encryptValue:(NSString *)value;
-(NSString *)decryptValue:(NSString *)value;
encryptValue
will be called for all values just before they are written into the file and decryptValue
will be called right after a value has been read from the file, before it is returned to the JS side.
Please share your thoughts and suggestions on this. I am happy to create a PR to implement this.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (4 by maintainers)
Top GitHub Comments
I understood your proposal, but still, this goes out of scope for this library. There is a delegate that you can implement for brownfield integration, so you could add encryption/decryption there to meet your use case? Otherwise I’m afraid you’ll have to maintain your own fork for that feature
I think what @Krizzu suggests makes sense. Encryption is not the responsibility of this library, and we already have a generic delegate you can implement to provide the capabilities you need. Your delegate could encrypt the value before data gets stored on disk, and similarly decrypt the data on retrieval. You’ll have to handle data storage yourself, but on iOS you can use either NSUserDefaults or Core Data or even write to plain files on disk depending on your scenario.