easy_encryption 0.0.1 easy_encryption: ^0.0.1 copied to clipboard
Easy encryption is a package which makes encrypting data easier. Using this package you can encrypt text data in a single line.
import 'package:easy_encryption/easy_encryption.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Easy Encrypt'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
EasyEncryption easyEncryption = EasyEncryption();
String message = "Hello World";
String encryptedMessage = "";
Future<String> encryptMyMessage(String message) async {
String encryptedMessage = await easyEncryption.encryptData(data: message);
return encryptedMessage;
}
Future<String> decryptMyMessage(String encryptedMessage) async {
String originalMessage = await easyEncryption.decryptData(data: encryptedMessage);
return originalMessage;
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
extendBodyBehindAppBar: true,
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Plain Text: $message',
style: TextStyle(fontSize: 20,),
),
TextButton(
onPressed: () async {
String result = await encryptMyMessage(message);
setState(() {
encryptedMessage = result;
});
}, child: Text("Encrypt"),),
Text("Encrypted Message: \n", style: TextStyle(fontSize: 20,),),
Text(encryptedMessage, ),
],
),
),
);
}
}