Flutter › Local Data Storage with SharedPreferences
Why should genuinely sensitive data, such as an authentication token or a password, never actually be stored using regular SharedPreferences, and what should genuinely be used instead?
IntermediateAnswer
SharedPreferences stores its own underlying data completely unencrypted in plain readable text on both Android and iOS, meaning any genuinely sensitive data such as an authentication token, a password, or any other kind of personal identifying information could potentially be read directly by another malicious app on a genuinely compromised or rooted device, and the flutter_secure_storage package should genuinely be used instead for any kind of sensitive data, since it properly relies on each platform's own genuine native secure storage mechanism, specifically Keychain on iOS and an encrypted Keystore backed implementation on Android, providing genuinely considerably stronger security protection.
// Avoid this for sensitive data
await prefs.setString('authToken', token);
// Prefer this instead
await secureStorage.write(key: 'authToken', value: token);Real-world example A banking app properly migrates its stored authentication token away from regular SharedPreferences over to flutter_secure_storage instead, meaningfully and considerably improving the genuine security protection of that particular sensitive piece of data.