@@ -68,6 +68,7 @@ class _CipherPageState extends State<CipherPage> {
68
68
final _cipherTextController = TextEditingController ();
69
69
final _macController = TextEditingController ();
70
70
Object ? _error;
71
+ String _decryptedText = '' ;
71
72
72
73
@override
73
74
Widget build (BuildContext context) {
@@ -190,6 +191,14 @@ class _CipherPageState extends State<CipherPage> {
190
191
const InputDecoration (labelText: 'Cleartext (text)' ),
191
192
),
192
193
const SizedBox (height: 10 ),
194
+ const Text ('Decrypted Text' ),
195
+ const SizedBox (height: 5 ),
196
+ Container (
197
+ color: Colors .grey.shade500,
198
+ padding: const EdgeInsets .all (4 ),
199
+ child: Text (_decryptedText),
200
+ ),
201
+ const SizedBox (height: 10 ),
193
202
TextField (
194
203
controller: _cipherTextController,
195
204
minLines: 1 ,
@@ -229,6 +238,9 @@ class _CipherPageState extends State<CipherPage> {
229
238
);
230
239
_cipherTextController.text = _toHex (secretBox.cipherText);
231
240
_macController.text = _toHex (secretBox.mac.bytes);
241
+
242
+ _decrypt ();
243
+
232
244
setState (() {
233
245
_error = null ;
234
246
});
@@ -241,4 +253,19 @@ class _CipherPageState extends State<CipherPage> {
241
253
return ;
242
254
}
243
255
}
256
+
257
+ Future <void > _decrypt () async {
258
+ final cipher = _cipher;
259
+
260
+ _decryptedText = utf8.decode (await cipher.decrypt (
261
+ SecretBox (
262
+ _fromHex (_cipherTextController.text),
263
+ nonce: _fromHex (_nonceController.text),
264
+ mac: Mac (_fromHex (_macController.text)),
265
+ ),
266
+ secretKey: SecretKeyData (
267
+ _fromHex (_secretKeyController.text),
268
+ ),
269
+ ));
270
+ }
244
271
}
0 commit comments