aes_gcm_crypto 0.0.1
aes_gcm_crypto: ^0.0.1 copied to clipboard
AES-GCM encryption and decryption utility with PBKDF2 key derivation support for Flutter apps.
example/lib/main.dart
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:aes_gcm_crypto/aes_gcm_crypto.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
runApp(const AesGcmExample());
}
class AesGcmExample extends StatefulWidget {
const AesGcmExample({super.key});
@override
State<AesGcmExample> createState() => _AesGcmExampleState();
}
class _AesGcmExampleState extends State<AesGcmExample> {
final AesGcmCrypto aesGcmCrypto = AesGcmCrypto.instance;
String plainText = "";
String masterKey = "";
String encrypted = "";
String decrypted = "";
@override
void initState() {
super.initState();
initialize();
}
Future<void> initialize() async {
if (!mounted) return;
if (kIsWeb) {
await aesGcmCrypto.init();
}
plainText = "hello";
debugPrint("PlainText: $plainText");
masterKey = "securePassword1234567890AWErTYuI";
debugPrint("MasterKey: $masterKey");
debugPrint(masterKey.length.toString());
encrypted = await aesGcmCrypto.encryptAesGcm(masterKey: masterKey, plainText: plainText);
debugPrint("Encrypted: $encrypted");
decrypted = await aesGcmCrypto.decryptAesGcm(masterKey: masterKey, cipherText: encrypted);
debugPrint("Decrypted: $decrypted");
setState(() {});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('AES-GCM Example'),
),
body: Center(
child: Container(
margin: const EdgeInsets.all(16),
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
borderRadius: BorderRadius.circular(8),
),
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: DataTable(
columnSpacing: 24,
headingRowColor: WidgetStateProperty.all(Colors.grey.shade200),
border: TableBorder.all(
color: Colors.grey.shade300,
width: 1,
),
columns: const [
DataColumn(label: Text('Type', style: TextStyle(fontWeight: FontWeight.bold))),
DataColumn(label: Text('Value', style: TextStyle(fontWeight: FontWeight.bold))),
],
rows: [
DataRow(cells: [
const DataCell(Text('Plain Text')),
DataCell(SelectableText(plainText)),
]),
DataRow(cells: [
const DataCell(Text('Master Key (32 characters)')),
DataCell(SelectableText(masterKey)),
]),
DataRow(cells: [
const DataCell(Text('Encrypted')),
DataCell(SelectableText(encrypted)),
]),
DataRow(cells: [
const DataCell(Text('Decrypted')),
DataCell(SelectableText(decrypted)),
]),
],
),
),
),
),
),
);
}
}