Skip to content

The encryptFile and decryptFile methods do not support streaming and will cause an OutOfMemoryError (OOM) when encrypting or decrypting large files. #2326

Description

@amd110

Preflight Checklist

  • I could not find a solution in the existing issues, docs, nor discussions

Describe your problem

Future encryptFile(Uint8List input) async {
final key = secureRandomBytes(32);
final iv = secureRandomBytes(16);
final data = CryptoUtils.aesCtr(input: input, key: key, iv: iv);
final hash = CryptoUtils.sha256(input: data);
return EncryptedFile(
data: data,
k: base64Url.encode(key).replaceAll('=', ''),
iv: base64.encode(iv).replaceAll('=', ''),
sha256: base64.encode(hash).replaceAll('=', ''),
);
}
Future<Uint8List?> decryptFile(EncryptedFile input) async {
if (base64.encode(await sha256(input.data)) !=
base64.normalize(input.sha256)) {
return null;
}

final key = base64decodeUnpadded(base64.normalize(input.k));
final iv = base64decodeUnpadded(base64.normalize(input.iv));
return await aesCtr.encrypt(input.data, key, iv);
}
File streams are not supported, and an OutOfMemoryError (OOM) will occur when encrypting or decrypting large files.

Describe your ideal solution

none

Version

No response

Security requirements

No response

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions