feat: Also hash the file on encryption and decryption

This commit is contained in:
2022-10-05 15:05:43 +02:00
parent 35138e102e
commit 31f33a0413
6 changed files with 167 additions and 30 deletions

View File

@@ -6,26 +6,52 @@ class AndroidCryptographyImplementation extends CryptographyImplementation {
final _methodChannel = const MethodChannel('me.polynom.moxplatform_android');
@override
Future<bool> encryptFile(String sourcePath, String destPath, Uint8List key, Uint8List iv, CipherAlgorithm algorithm) async {
final result = await _methodChannel.invokeMethod<bool>('encryptFile', [
Future<CryptographyResult?> encryptFile(String sourcePath, String destPath, Uint8List key, Uint8List iv, CipherAlgorithm algorithm, String hashSpec) async {
final dynamic resultRaw = await _methodChannel.invokeMethod<dynamic>('encryptFile', [
sourcePath,
destPath,
key,
iv,
algorithm.toInt(),
hashSpec,
]);
return result ?? false;
if (resultRaw == null) return null;
final result = Map<String, Uint8List>.from(resultRaw as Map<String, dynamic>);
return CryptographyResult(
result['plaintext_hash']!,
result['ciphertext_hash']!,
);
}
@override
Future<bool> decryptFile(String sourcePath, String destPath, Uint8List key, Uint8List iv, CipherAlgorithm algorithm) async {
final result = await _methodChannel.invokeMethod<bool>('decryptFile', [
Future<CryptographyResult?> decryptFile(String sourcePath, String destPath, Uint8List key, Uint8List iv, CipherAlgorithm algorithm, String hashSpec) async {
final dynamic resultRaw = await _methodChannel.invokeMethod<dynamic>('decryptFile', [
sourcePath,
destPath,
key,
iv,
algorithm.toInt(),
hashSpec,
]);
return result ?? false;
if (resultRaw == null) return null;
final result = Map<String, Uint8List>.from(resultRaw as Map<String, dynamic>);
return CryptographyResult(
result['plaintext_hash']!,
result['ciphertext_hash']!,
);
}
@override
Future<Uint8List?> hashFile(String path, String hashSpec) async {
final dynamic resultsRaw = await _methodChannel.invokeMethod<dynamic>('hashFile', [
path,
hashSpec,
]);
if (resultsRaw == null) return null;
return resultsRaw as Uint8List;
}
}