Question #265MediumFlutter BasicsImportant

How flutter secure storage plugin stores the key in both android and iOS ?

#flutter#storage#android#ios

Answer

Flutter Secure Storage Plugin

flutter_secure_storage uses platform-specific secure storage:


Android Implementation

Uses Android Keystore (hardware-backed when available):

java
// Under the hood - Android code
KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore");
keyStore.load(null);
SecretKey key = (SecretKey) keyStore.getKey("key_alias", null);

Process:

  1. Data encrypted with AES key
  2. Key stored in AndroidKeystore
  3. Key protected by device lock screen
  4. Hardware acceleration if available

iOS Implementation

Uses iOS Keychain:

swift
// iOS Keychain - secure by default
SecurityClass: kSecClassGenericPassword
AccessibleAttribute: kSecAttrAccessibleWhenUnlockedThisDeviceOnly

Process:

  1. Data encrypted and stored in Keychain
  2. Protected by device passcode
  3. Hardware-backed on modern devices
  4. Requires authentication to access

Comparison

FeatureAndroidiOS
StorageAndroidKeystoreKeychain
EncryptionAESHardware
HardwareWhen availableAlways
Access ControlDevice lockBiometric/Passcode

Usage

dart
final storage = FlutterSecureStorage();

await storage.write(key: 'token', value: 'secret_token');
final token = await storage.read(key: 'token');
await storage.delete(key: 'token');

Security: Both methods are cryptographically secure.