encrypto_flutter 1.0.0
encrypto_flutter: ^1.0.0 copied to clipboard
RSA and DES encryption
example/lib/main.dart
import 'package:encrypto_flutter/encrypto_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter_des/flutter_des.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String encryptedAndDecrypted = '';
bool _isEditingText = true;
late TextEditingController controller;
late Encrypto encrypto;
@override
void initState() {
// TODO: implement initState
controller = TextEditingController();
encrypto = Encrypto(Encrypto.RSA);
super.initState();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Column(
children: [
_editTitleTextField(),
// EditableText(
// controller: controller,
// focusNode: FocusNode(),
// cursorColor: Colors.blue,
// backgroundCursorColor: Colors.blue,
// style: const TextStyle(color: Colors.black),
// ),
ElevatedButton(
onPressed: () {
var encrypted = encrypto.encrypt(controller.text, publicKey: encrypto.getPublicKey());
var decrypted = encrypto.decrypt(encrypted);
setState(() {
encryptedAndDecrypted =
'encrypted base64 String: $encrypted\ndecrypted String: $decrypted';
});
},
child: const Text("Encrypt and Decrypt")),
Text(encryptedAndDecrypted),
],
),
),
);
}
Widget _editTitleTextField() {
if (_isEditingText) {
return Center(
child: TextField(
onSubmitted: (newValue) {
setState(() {
encryptedAndDecrypted = newValue;
_isEditingText = false;
});
},
autofocus: true,
controller: controller,
),
);
}
return InkWell(
onTap: () {
setState(() {
_isEditingText = true;
});
},
child: Text(
encryptedAndDecrypted,
style: const TextStyle(
color: Colors.black,
fontSize: 18.0,
),
));
}
}