feat: Bring over the cryptography API from moxplatform

This commit is contained in:
2023-09-08 19:25:26 +02:00
parent fd91ccc46f
commit b52ca03eff
12 changed files with 623 additions and 51 deletions

View File

@@ -1,3 +1,5 @@
import 'dart:io';
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:moxxy_native/moxxy_native.dart';
@@ -5,9 +7,16 @@ void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
MyAppState createState() => MyAppState();
}
class MyAppState extends State<MyApp> {
String? imagePath;
@override
Widget build(BuildContext context) {
return MaterialApp(
@@ -44,6 +53,48 @@ class MyApp extends StatelessWidget {
},
child: const Text('Generic multi-picker'),
),
TextButton(
onPressed: () async {
final result = await MoxxyPickerApi().pickFiles(FilePickerType.image, false);
if (result.isEmpty) return;
final encDest = result.first! + '.enc';
final decDest = result.first! + '.dec';
final encResult = await MoxxyCryptographyApi().encryptFile(
result.first!,
encDest,
Uint8List.fromList(List.filled(32, 1)),
Uint8List.fromList(List.filled(16, 2)),
CipherAlgorithm.aes256CbcPkcs7,
'SHA-256',
);
if (encResult == null) {
print('Failed to encrypt file');
return;
}
final decResult = await MoxxyCryptographyApi().decryptFile(
encDest,
decDest,
Uint8List.fromList(List.filled(32, 1)),
Uint8List.fromList(List.filled(16, 2)),
CipherAlgorithm.aes256CbcPkcs7,
'SHA-256',
);
if (decResult == null) {
print('Failed to decrypt file');
return;
}
setState(() {
imagePath = decDest;
});
},
child: Text('Test cryptography'),
),
if (imagePath != null)
Image.file(File(imagePath!)),
],
),
),