Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

decrypt huge aes-ctr encrypted file #157

Open
MetaiR opened this issue Mar 15, 2022 · 0 comments
Open

decrypt huge aes-ctr encrypted file #157

MetaiR opened this issue Mar 15, 2022 · 0 comments

Comments

@MetaiR
Copy link

MetaiR commented Mar 15, 2022

hi,
first of all I am pretty new in flutter stuff so please forgive me if my question seems dumb to u

I want to decrypt huge files (the file size is somewhere between 500MB ~ 1GB).
I am using this code to read file as stream and decrypt it but I don't know if this is ok or not and need some help if it can be achieved differently:

this is my code:

Future<bool> decryptStream(String input) async {
    try {
      final iv = EncryptPlugin.IV(Uint8List.fromList(hex.decode('hexed-iv')));
      final key = EncryptPlugin.Key.fromUtf8('my-secret-key');
      final ctr = pc.CTRStreamCipher(pc.AESEngine())
        ..init(false, pc.ParametersWithIV(pc.KeyParameter(key.bytes), iv.bytes));

      final outputFile = File('${privateAppDir.path}/op/$input.mp4');
      final output = outputFile.openWrite(mode: FileMode.writeOnlyAppend);

      await File(privateAppDir.path + '/' + input).openRead()
        .map((List<int> data) => Uint8List.fromList(data))
        .map((Uint8List data) => ctr.process(data))
        .map((Uint8List data) => List.from(data))
        .pipe(output);

      return true;
    } catch (exc) {
      print(exc);
      return false;
    }
  }

please guide me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant