encrypted_shared_preferences icon indicating copy to clipboard operation
encrypted_shared_preferences copied to clipboard

Encryption key must not be saved in SharedPreferences

Open espresso3389 opened this issue 4 years ago • 5 comments

I've researched how the encryption key is stored in encrypted_shared_preference and found that it is simply stored in SharedPreferences. Basically, such sensitive info must be stored in keychain or something like it.

espresso3389 avatar Sep 17 '21 09:09 espresso3389

Probably for easier backup/restore to google cloud?

biji avatar Dec 20 '21 01:12 biji

Totally agree. For those with more strict security requirements, I would recommend to add an API that allows to provide your own encryption key (as a string) instead of generating it randomly.

PasqualePuzio avatar Mar 15 '22 14:03 PasqualePuzio

I see maintainers have failed to understand the gravity of the situation. Here randomKeyKey stores the encryption key and is stored as plain text in Shared Preference. https://github.com/roulljdh/encrypted_shared_preferences/blob/1d49456257e293ffad9a01ff45b5453565c5dfc0/lib/encrypted_shared_preferences.dart#L37-L42

It's like locking your door with the best of the best lock and then hanging your key just beside the lock.

Storing the security key as plain text in Shared Preference is not at all the recommended security practice.

Here is the paradox "if maintainers thinks that Shared Preference is secure enough to store the encryption key then why need encrypted shared preference in the first place?"

TL;DR

  • PROBLEM: The current implementation of this plugin is insecure and for a hacker, it would take minutes to hack into the data.
  • SOLUTION: Use Keystore and Keychain for storing the encryption keys.

keshav-space avatar Oct 30 '22 23:10 keshav-space

I'm kind of shocked that this package is in the top 5% of popular packages (95% popularity).

Calling this package "encrypted_shared_preferences" is very misleading:

  • Like @keshav-space and @espresso3389 said, saving the key in plain text is not secure at all. This is just secruity through obscurity, not secure encryption.
  • The name suggests that the package makes use of Androids EncryptedSharedPreferences, which it does not.

Anyone who wants use encryption to store data should either use flutter_secure_storage, or even better biometric_storage.

sebkoller avatar Nov 10 '22 13:11 sebkoller

Hi, is this issue resolved now?

allomy avatar Jan 06 '23 06:01 allomy