I am trying to build an app in flutter using api tokens and i would like to know if SharedPrefences and flutter_secure_storage packages do the same things or if they are different.
shared_preferences is a Flutter plugin that allows you to save data in a key-value format so you can easily retrieve it later. Behind the scenes, it uses the aptly named SharedPreferences on Android and the similar UserDefaults on iOS.
A Flutter plugin to store data in secure storage: Keychain is used for iOS. AES encryption is used for Android. AES secret key is encrypted with RSA and RSA key is stored in KeyStore.
Flutter shared preferences is actually implemented as an in-memory cache. The first time that you call SharedPreferences. getInstance() all the current values are read from NSUserDefaults (on iOS) and SharedPreferences (on Android) and cached in memory.
flutter_secure_storage package uses SharedPreferences with MODE_PRIVATE as you can see here:
preferences = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
It also uses additional encryption via AES. From readme:
AES encryption is used for Android. AES secret key is encrypted with RSA and RSA key is stored in KeyStore
. You can find details in the source code.
As for secure tokens and other sensitive data, it would be safer to use flutter_secure_storage
instead of raw SharedPreferences with private mode.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With