Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between SharedPrefernces and Flutter_secure_storage packages when building an app in flutter? or do they do the same thing?

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.

like image 884
Ugocode Avatar asked Jan 12 '21 06:01

Ugocode


People also ask

What is the use of SharedPreferences in Flutter?

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.

What is Flutter_secure_storage?

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.

Where shared preferences are stored in Flutter?

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.


1 Answers

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.

like image 110
Mol0ko Avatar answered Oct 15 '22 11:10

Mol0ko