simple_rsa 0.0.5 simple_rsa: ^0.0.5 copied to clipboard
Flutter plugin to encrypt and decrypt string with a public and a private key
import 'package:flutter/material.dart';
import 'package:simple_rsa/simple_rsa.dart';
void main() => runApp(App());
class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Simple RSA Encryption',
home: Home(),
);
}
}
class Home extends StatefulWidget {
@override
HomeState createState() => HomeState();
}
class HomeState extends State<Home> {
final PUBLIC_KEY =
"MIIBITANBgkqhkiG9w0BAQEFAAOCAQ4AMIIBCQKCAQBuAGGBgg9nuf6D2c5AIHc8" +
"vZ6KoVwd0imeFVYbpMdgv4yYi5obtB/VYqLryLsucZLFeko+q1fi871ZzGjFtYXY" +
"9Hh1Q5e10E5hwN1Tx6nIlIztrh5S9uV4uzAR47k2nng7hh6vuZ33kak2hY940RSL" +
"H5l9E5cKoUXuQNtrIKTS4kPZ5IOUSxZ5xfWBXWoldhe+Nk7VIxxL97Tk0BjM0fJ3" +
"8rBwv3++eAZxwZoLNmHx9wF92XKG+26I+gVGKKagyToU/xEjIqlpuZ90zesYdjV+" +
"u0iQjowgbzt3ASOnvJSpJu/oJ6XrWR3egPoTSx+HyX1dKv9+q7uLl6pXqGVVNs+/" +
"AgMBAAE=";
final PRIVATE_KEY =
"MIIEoQIBAAKCAQBuAGGBgg9nuf6D2c5AIHc8vZ6KoVwd0imeFVYbpMdgv4yYi5ob" +
"tB/VYqLryLsucZLFeko+q1fi871ZzGjFtYXY9Hh1Q5e10E5hwN1Tx6nIlIztrh5S" +
"9uV4uzAR47k2nng7hh6vuZ33kak2hY940RSLH5l9E5cKoUXuQNtrIKTS4kPZ5IOU" +
"SxZ5xfWBXWoldhe+Nk7VIxxL97Tk0BjM0fJ38rBwv3++eAZxwZoLNmHx9wF92XKG" +
"+26I+gVGKKagyToU/xEjIqlpuZ90zesYdjV+u0iQjowgbzt3ASOnvJSpJu/oJ6Xr" +
"WR3egPoTSx+HyX1dKv9+q7uLl6pXqGVVNs+/Ag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VFukiZoY23fpXu9FT1YDW28xrHepFfb1EamynvqPl" +
"O88CgYAvzzSt+d4FG03jwObhdZrmZxaJk0jkKu3JkxUmav9Zav3fDTX1hYxDNTLi" +
"dazvUFfqN7wqSSPqajQmMoTySxmLI8gI4qC0QskB4lT1A8OfmjcDwbUzQGam5Kpz" +
"ymmKJA9DgQpPgEIjHAnw2dUDR+wI/Loywb0AGLIbszseCOlc2Q==";
final myController = TextEditingController();
String _stringEncoded = '';
@override
void dispose() {
myController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("Simple RSA Encryption"),
),
body: Padding(
padding: const EdgeInsets.all(8.0),
child: new ListView(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: TextField(
controller: myController,
decoration: InputDecoration(
hintText: "Write the text to be encrypted",
),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
RaisedButton(
child:
_stringEncoded.isEmpty ? Text("ENCODE") : Text("DECODE"),
color: Colors.yellow,
onPressed: () async {
String tmp = "";
try {
if (_stringEncoded.isEmpty) {
final text = myController.text;
if (text.isNotEmpty) {
final tmp = await encryptString(
myController.text, PUBLIC_KEY);
setState(() {
_stringEncoded = tmp;
myController.clear();
});
}
} else {
tmp = await decryptString(_stringEncoded, PRIVATE_KEY);
setState(() {
_stringEncoded = "";
myController.text = tmp;
});
}
} catch (e) {
print(e);
}
},
),
RaisedButton(
child: Text("DECODE"),
color: Colors.red,
onPressed: () async {
String tmp = "";
if (_stringEncoded.isNotEmpty) {
try {
tmp =
await decryptString(_stringEncoded, PRIVATE_KEY);
setState(() {
_stringEncoded = "";
myController.text = tmp;
});
} catch (e) {
print(e);
}
}
}),
RaisedButton(
child: Text("RESET"),
color: Colors.blue,
onPressed: () {
setState(() {
_stringEncoded = "";
myController.clear();
});
},
),
],
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Card(
color: Colors.orangeAccent,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: <Widget>[
Text("STRING ENCODED"),
Divider(),
Text(_stringEncoded),
],
),
),
),
),
],
),
),
);
}
}