martinkasa / capacitor-secure-storage-plugin

Capacitor plugin for storing string values securly on iOS and Android.
MIT License
153 stars 55 forks source link

Change to EncryptedSharedPreferences for Android? #13

Open tehnrd opened 4 years ago

tehnrd commented 4 years ago

Disclaimer, I'm fairly new to Android and Capacitor development.

For Android, is there a reason EncryptedSharedPreferences aren't used? It seems like this would greatly simplify the plugin and essentially remove the need for the entire PasswordStorageHelper.java class.

martinkasa commented 4 years ago

There is no any specific reason. As is stated in README, code for android is based of https://www.apriorit.com/dev-blog/432-using-androidkeystore . If we want to change the way passwords are stored, then we would need to create some migration process, so users do not lost their data.

tehnrd commented 4 years ago

True, the migration piece probably doesn't make this worth the effort. I appreciate the response. I might take a stab and creating a similar plugin as I need to learn this stuff anyway.

tehnrd commented 4 years ago

Hey @martinkasa , I'd like to reopen this discussion and take a stab at delivering this feature. I see two main advantages.

The first being it would greatly simplify the encryption process for Android and use the standard encryption methods/practices provided by Android.

The second and primary driver is that it would also allow for much easier access to the storage if you need to access values from a background process. For example, 90% of the app might be an Ionic/Capacitor app, but perhaps there are some background processes that need to get an acessToken/refreshToken for to sync background data with an external API.

Implementation seems pretty straightforward but curious your thoughts on the best way to run a migration? Or perhaps not run a migration and have a flag to determine what time of encryption process is used. This way the app could decide and control if/when it wants to migrate the data and be in full control of that process.

SavageCore commented 4 years ago

I would say on data access perform the migration, if you set an existing key it would remove from the old store then add to Encrypted, similarily if you get the data it would be moved. That way the API stays the same and the transition is seamless.