This repository has been archived on 2023-09-08. You can view files and clone it, but cannot push or open issues or pull requests.
moxplatform/packages/moxplatform_android/lib/src/crypto_android.dart

58 lines
1.8 KiB
Dart

import 'dart:typed_data';
import 'package:flutter/services.dart';
import 'package:moxplatform_platform_interface/moxplatform_platform_interface.dart';
class AndroidCryptographyImplementation extends CryptographyImplementation {
final _methodChannel = const MethodChannel('me.polynom.moxplatform_android');
@override
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,
]);
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<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,
]);
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;
}
}