Add API to use AesCrypt to encrypt and decrypt data directly
This commit is contained in:
parent
81db6e73d1
commit
aa2890107f
3 changed files with 28 additions and 2 deletions
|
@ -1,10 +1,14 @@
|
|||
import 'dart:typed_data';
|
||||
|
||||
import 'dart:io' as io;
|
||||
import 'package:aes_crypt/aes_crypt.dart';
|
||||
import 'package:computer/computer.dart';
|
||||
import 'package:encrypt/encrypt.dart';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:photos/core/configuration.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
class CryptoUtil {
|
||||
static String getBase64EncodedSecureRandomString({int length = 32}) {
|
||||
return SecureRandom(length).base64;
|
||||
|
@ -48,6 +52,17 @@ class CryptoUtil {
|
|||
return Computer().compute(runEncryptDataToFile, param: args);
|
||||
}
|
||||
|
||||
static Future<String> encryptDataToData(Uint8List source, String key) async {
|
||||
final destinationPath =
|
||||
Configuration.instance.getTempDirectory() + Uuid().v4();
|
||||
return encryptDataToFile(source, destinationPath, key).then((value) {
|
||||
final file = io.File(destinationPath);
|
||||
final data = file.readAsStringSync(encoding: utf8);
|
||||
file.deleteSync();
|
||||
return data;
|
||||
});
|
||||
}
|
||||
|
||||
static Future<void> decryptFileToFile(
|
||||
String sourcePath, String destinationPath, String key) async {
|
||||
final args = Map<String, String>();
|
||||
|
@ -63,6 +78,16 @@ class CryptoUtil {
|
|||
args["source"] = sourcePath;
|
||||
return Computer().compute(runDecryptFileToData, param: args);
|
||||
}
|
||||
|
||||
static Future<String> decryptDataToData(String source, String key) {
|
||||
final sourcePath = Configuration.instance.getTempDirectory() + Uuid().v4();
|
||||
final file = io.File(sourcePath);
|
||||
file.writeAsStringSync(source);
|
||||
return decryptFileToData(sourcePath, key).then((value) {
|
||||
file.deleteSync();
|
||||
return utf8.decode(value);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> runEncryptFileToFile(Map<String, String> args) {
|
||||
|
|
|
@ -764,12 +764,12 @@ packages:
|
|||
source: hosted
|
||||
version: "3.4.2"
|
||||
uuid:
|
||||
dependency: transitive
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: uuid
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.2.0"
|
||||
version: "2.2.2"
|
||||
vector_math:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
@ -64,6 +64,7 @@ dependencies:
|
|||
uni_links: ^0.4.0
|
||||
flutter_svg: ^0.18.1
|
||||
crisp: ^0.1.3
|
||||
uuid: 2.2.2
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
|
Loading…
Add table
Reference in a new issue