Protect mobile secrets using Flutter BiometricPrompt and Android Keystore AES-256 storage. Complete tutorial for banking-grade authentication security. This practical guide covers step-by-step setup, real-world code snippets, security hardening, and common production edge cases.
Executive Summary & Key Takeaway (AEO)
Storing sensitive tokens (JWTs, refresh credentials, encryption keys) inside standard SharedPreferences or plain files on Android exposes them to root extraction and backup vulnerabilities. A banking-grade security architecture pairs theflutter_secure_storageplugin (which generates an AES-256 GCM key stored inside the hardware-backed Android Keystore) withlocal_auth(Android BiometricPrompt API) to unlock credentials strictly upon physical fingerprint or facial confirmation.
The Hardware-Backed Mobile Security Architecture
[ User Action: Open Wallet / View Balance ]
│
▼
[ Prompt Biometric Auth ]
(local_auth BiometricPrompt)
│
┌─────────┴─────────┐
▼ (Failed/Canceled) ▼ (Success: Fingerprint/Face)
[ Lock App ] [ Request Master Key from Android Keystore ]
│
▼
[ Decrypt AES-256 Session Token ]
│
▼
[ Execute Authenticated API Call ]
Step 1: Android Manifest Permissions & Configuration
Update android/app/src/main/AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.USE_BIOMETRIC"/>
<application
android:label="SecureApp"
android:icon="@mipmap/ic_launcher">
<!-- FragmentActivity required for Android BiometricPrompt -->
</application>
</manifest>
Verify that your MainActivity.kt inherits from FlutterFragmentActivity:
package com.devpatternlabs.secureapp
import io.flutter.embedding.android.FlutterFragmentActivity
class MainActivity: FlutterFragmentActivity() {
}
Step 2: Encrypted Storage Configuration
Initialize flutter_secure_storage with Android Keystore options:
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
class SecureVaultService {
static const _storage = FlutterSecureStorage(
aOptions: AndroidOptions(
encryptedSharedPreferences: true,
keyCipherAlgorithm: KeyCipherAlgorithm.RSA_ECB_PKCS1Padding,
storageCipherAlgorithm: StorageCipherAlgorithm.AES_GCM_NoPadding,
),
);
static Future<void> saveAuthToken(String token) async {
await _storage.write(key: 'jwt_auth_token', value: token);
}
static Future<String?> getAuthToken() async {
return await _storage.read(key: 'jwt_auth_token');
}
static Future<void> clearVault() async {
await _storage.deleteAll();
}
}
Step 3: Biometric Challenge with local_auth
Trigger the hardware biometric challenge before unlocking the stored secret:
import 'package:flutter/services.dart';
import 'package:local_auth/local_auth.dart';
class BiometricAuthManager {
final LocalAuthentication _auth = LocalAuthentication();
Future<bool> authenticateUser() async {
final bool canAuthenticateWithBiometrics = await _auth.canCheckBiometrics;
final bool canAuthenticate = canAuthenticateWithBiometrics || await _auth.isDeviceSupported();
if (!canAuthenticate) {
return false; // Fallback to PIN / Master Password
}
try {
return await _auth.authenticate(
localizedReason: 'Please scan your fingerprint or face to authenticate',
options: const AuthenticationOptions(
stickyAuth: true,
biometricOnly: true,
),
);
} on PlatformException catch (e) {
print('Biometric error: ${e.message}');
return false;
}
}
}
Security Audit Best Practices
- Enable
encryptedSharedPreferences: true: Binds encryption keys to the Android Keystore hardware security module (HSM). - Prohibit Plaintext Caching: Never cache decrypted tokens in unencrypted Dart global variables or static state managers.
Mobile Security by Dev Pattern Labs
Building fintech, healthcare, or enterprise mobile apps? Dev Pattern Labs architects hardened mobile solutions with strict compliance standards. Explore our Mobile Engineering Services or book a 14-Day Delivery Sprint.
Companion Flutter Guides
Written by Dev Pattern LabsCore Engineering
Dev Pattern Labs is an engineering lab and digital consultancy specializing in custom Next.js web applications, WooCommerce REST API integrations, and workflow automation for growing businesses.
Recommended Companion Articles

Architecting a Production-Grade Ride-Hailing Engine with Flutter & Firebase
Architect an enterprise ride-hailing engine with Flutter 3 and Firebase. Cut map API costs by 90% using hybrid Carto tiles and atomic Firestore claiming.

Building Flutter Android App Bundles with GitHub Actions CI/CD
Automate Flutter Android builds with GitHub Actions. Securely sign AABs with Java keystore secrets, cache Gradle, and deploy to Google Play Track.

Flutter Isolates and Background Processing in Android Studio
Offload heavy JSON decoding, image filtering, and cryptography to Flutter background Isolates without freezing the Android UI thread or dropping frames.
