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

Decrypting content takes a comically long time #137

Open
jeffkowalski opened this issue Feb 17, 2025 · 4 comments
Open

Decrypting content takes a comically long time #137

jeffkowalski opened this issue Feb 17, 2025 · 4 comments
Labels
enhancement New feature or request

Comments

@jeffkowalski
Copy link

I've created a few sample org files, with encrypted content denoted using the :crypt: tag.
In emacs, I assign the password "foobar".
On my Thinkpad, both the encryption and subsequent decryption are nearly intantaneous.
The same file, when opened in Orgro on my Android phone, takes a very long time to decrypt - over a minute, and more typically 65-80 seconds.

Here is an example file that exhibits the disappointing decrypt time:

# -*- buffer-auto-save-file-name: nil; -*-
#+title: Stuff

* this heading is not private

* this, however, is private :crypt:
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

* this heading is, again, not private

when encrypted using passphrase "foobar", it's

# -*- buffer-auto-save-file-name: nil; -*-
#+title: Stuff

* this heading is not private

* this, however, is private :crypt:
-----BEGIN PGP MESSAGE-----

jA0ECQMKBFBWkxStKDP/0sCKAQHIrf29+ADSslvuenHA6A6AQumIi8BUl8HnUXvJ
uYIBbmdLKFR+hSGyRt77fOREfU5E3/FB3TUdeAkGdNPdyPSD4qs/Aovee5vH32IX
1Xxnqb7yEc2AY3nQrdOTD2YGBXNmWD/bY/r+Ie76LX4rk9p1WAqCKE1n6boomMlY
TlbK/EbIkF1xguWvNGJDaU0wMvSEQDINRnO7gDSeaM1UKO/TCS/0VKv4K8ctIr2W
xtFXvvMsiMMYWfBzRnwZvs0nElr1Hzk7gkebooZa4Au4ZhkgxS4QEG/Pa8JqP9Kp
Yd9lI4IbbnVp92gAL4Z+cLQztygAUey1+9EzK4tP0I6pkUkvdSe652u7aICXJ3kz
/r20VMR5051klVsJcRHOFuR+NZBy7CVxLLNoK5VIcYKfFTR25s5s94QhuCzGa7LT
UcYywR0BCNxbav/x
=+kk8
-----END PGP MESSAGE-----

* this heading is, again, not private
@amake
Copy link
Owner

amake commented Feb 18, 2025

I've also experienced slow encryption/decryption times with my Pixel 2. It's much better on a recent iPhone.

There's not much I can do about this. I am at the mercy of

  • the PGP implementation (I don't have the knowledge to improve this)
  • weak Android device CPUs

If there is a better PGP implementation out there then I'm willing to switch, but last time I looked into it the current library (dart_pg) was the only one that fit the bill in that it allowed synchronous execution. It's possible openpgp may be faster, but it is asynchronous so I'd have to rearchitect a bunch of things to accommodate it.

@jeffkowalski
Copy link
Author

Maybe a synchronous wrapper around openpgp?

String encryptSymmetricBlocking(String plaintext, String password) {
  // Use a Completer to hold the eventual result
  final completer = Completer<String>();

  // Call the async method
  FlutterOpenPGP.encryptSymmetric(
    data: plaintext,
    passphrase: password,
  ).then(completer.complete).catchError(completer.completeError);

  // Busy-wait (spin) until the completer finishes:
  // WARNING: This will block the UI thread in Flutter!
  while (!completer.isCompleted) {
    // You could insert a small delay/sleep here, but it still blocks.
  }

  // Return the completed value or throw if error
  if (completer.isCompleted) {
    return completer.future.valueOrCancellation("")!;
  }
  throw Exception("Encryption failed unexpectedly");
}

@amake amake changed the title decrypting content takes a comically long time Decrypting content takes a comically long time Mar 1, 2025
@amake amake added the enhancement New feature or request label Mar 1, 2025
@amake
Copy link
Owner

amake commented Mar 1, 2025

I wouldn't consider a hack like that.

After doing all the legwork to add async plumbing to all my code, I realized that the core of openpgp is FFI, not MethodChannel (at least on non-web platforms) and FFI doesn't need to be async except to provide a unified API covering web as well. I've requested a sync API at jerson/flutter-openpgp#79, but I was also able to make my own with minor modifications on my fork.

Encryption/decryption speed with openpgp is much faster. Test it in v1.55.0, coming soon:

@jeffkowalski
Copy link
Author

Great work! Thank you. I've enabled beta versions (just in case) and look forward to testing v1.55.0.

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

No branches or pull requests

2 participants