|
@@ -119,7 +119,21 @@ class CryptoUtil {
|
|
|
EncryptionAttribute(bytes: encryptedData));
|
|
|
}
|
|
|
|
|
|
- static ChaChaEncryptionResult encryptStream(Uint8List source, Uint8List key) {
|
|
|
+ static Future<Uint8List> decrypt(
|
|
|
+ Uint8List cipher, Uint8List key, Uint8List nonce,
|
|
|
+ {bool background = false}) async {
|
|
|
+ final args = Map<String, dynamic>();
|
|
|
+ args["cipher"] = cipher;
|
|
|
+ args["nonce"] = nonce;
|
|
|
+ args["key"] = key;
|
|
|
+ if (background) {
|
|
|
+ return Computer().compute(cryptoSecretboxOpenEasy, param: args);
|
|
|
+ } else {
|
|
|
+ return cryptoSecretboxOpenEasy(args);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ static ChaChaEncryptionResult encryptChaCha(Uint8List source, Uint8List key) {
|
|
|
final initPushResult =
|
|
|
Sodium.cryptoSecretstreamXchacha20poly1305InitPush(key);
|
|
|
final encryptedData = Sodium.cryptoSecretstreamXchacha20poly1305Push(
|
|
@@ -127,10 +141,10 @@ class CryptoUtil {
|
|
|
source,
|
|
|
null,
|
|
|
Sodium.cryptoSecretstreamXchacha20poly1305TagFinal);
|
|
|
- return ChaChaEncryptionResult(encryptedData, initPushResult.header);
|
|
|
+ return ChaChaEncryptionResult(encryptedData, header: initPushResult.header);
|
|
|
}
|
|
|
|
|
|
- static Uint8List decryptStream(
|
|
|
+ static Uint8List decryptChaCha(
|
|
|
Uint8List source, Uint8List key, Uint8List header) {
|
|
|
final pullState =
|
|
|
Sodium.cryptoSecretstreamXchacha20poly1305InitPull(header, key);
|
|
@@ -139,20 +153,6 @@ class CryptoUtil {
|
|
|
return pullResult.m;
|
|
|
}
|
|
|
|
|
|
- static Future<Uint8List> decrypt(
|
|
|
- Uint8List cipher, Uint8List key, Uint8List nonce,
|
|
|
- {bool background = false}) async {
|
|
|
- final args = Map<String, dynamic>();
|
|
|
- args["cipher"] = cipher;
|
|
|
- args["nonce"] = nonce;
|
|
|
- args["key"] = key;
|
|
|
- if (background) {
|
|
|
- return Computer().compute(cryptoSecretboxOpenEasy, param: args);
|
|
|
- } else {
|
|
|
- return cryptoSecretboxOpenEasy(args);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
static Future<ChaChaAttributes> encryptFile(
|
|
|
String sourceFilePath,
|
|
|
String destinationFilePath,
|