Whether you’re building a finance tracker, secure messaging app, or just storing sensitive preferences, securing local data is non-negotiable. Flutter makes cross-platform development easy, but encryption support isn’t always straightforward out of the box. That’s where this simple yet powerful project comes in—flutter-cryptography
.
Built around the cryptography
package, this project demonstrates a practical way to encrypt and decrypt data locally in a Flutter app, using AES-GCM and securely storing keys with flutter_secure_storage
.
When storing sensitive data—like access tokens, passwords, or any personal user information—on a device, plain text is not an option. Mobile phones can be compromised, apps can be reverse-engineered, and sensitive data can leak. Encryption ensures:
The flutter-cryptography
repository shows a complete encryption workflow in Dart:
flutter_secure_storage
.The Cryptor
class wraps all this logic, making it reusable and simple to integrate into any app.
final encrypted = await cryptor.encrypt('secret message');
final decrypted = await cryptor.decrypt(encrypted);
It’s that straightforward.
AES-GCM (Galois/Counter Mode) is a modern encryption standard that not only encrypts data but also verifies its integrity. It’s fast, secure, and widely supported—ideal for mobile apps.
To get started, you’ll need these dependencies in your pubspec.yaml
:
dependencies:
cryptography: ^2.0.3
flutter_secure_storage: ^9.0.0
Make sure you also configure flutter_secure_storage
properly for iOS and Android. See their setup instructions for platform-specific steps.
This example keeps things simple by generating a single key and storing it securely on the device. In real-world apps, you may want:
If you’re looking to build Flutter apps that respect user privacy and handle sensitive data securely, flutter-cryptography
is a solid starting point. It’s small, focused, and easy to adapt.
Want to try it yourself? 🔗 View the code on GitHub.