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

Look for help, the compression of KeyOptions does not work. #69

Open
itlwy opened this issue May 8, 2024 · 0 comments
Open

Look for help, the compression of KeyOptions does not work. #69

itlwy opened this issue May 8, 2024 · 0 comments

Comments

@itlwy
Copy link

itlwy commented May 8, 2024

hello @jerson , when I use this library, I hope to specify the compression and cipher field of the KeyOptions class, but it doesn't work. How can i fix it?
The example code is as follow:

class TestOpenPGP extends StatefulWidget {
  const TestOpenPGP({super.key});

  @override
  State<TestOpenPGP> createState() => _TestOpenPGPState();
}

class _TestOpenPGPState extends State<TestOpenPGP> {
  String _encryptData = '';
  KeyPair? _keyPair;

  Future<KeyPair> get keyPair async {
    _keyPair ??= await OpenPGP.generate();
    return _keyPair!;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: SizedBox(
      width: double.infinity,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          ElevatedButton(
              onPressed: _testEncryptPerformance, child: Text('test encrypt')),
          ElevatedButton(
              onPressed: _testDecryptPerformance, child: Text('test decrypt')),
        ],
      ),
    ));
  }

  void _testEncryptPerformance() async {
    final keyOptions = KeyOptions()
      ..compression = Compression.ZLIB
      ..cipher = Cipher.AES128
      ..compressionLevel = 1;
    final publicKey = (await keyPair).publicKey;
    _encryptData = await OpenPGP.encrypt(
        '[{"title":"hello", "content":"world"},{"title":"hello", "content":"world"},{"title":"hello", "content":"world"},{"title":"hello", "content":"world"}]',
        publicKey,
        options: keyOptions);
    print('====> encryptData: $_encryptData');
  }

  void _testDecryptPerformance() async {
    final keyOptions = KeyOptions()
      ..compression = Compression.NONE
      ..cipher = Cipher.CAST5
      ..compressionLevel = 1;
    final privateKey = (await keyPair).privateKey;
    final decryptData = await OpenPGP.decrypt(
        _encryptData, privateKey, "password",
        options: keyOptions);
    print('====> decryptData: $decryptData');
  }
}

My Flutter SDK info is as follow:

% flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.16.9, on macOS 14.1.1 23B81 darwin-arm64, locale zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.0.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2023.3)
[✓] VS Code (version 1.89.0)
[✓] Connected device (4 available)
[✓] Network resources

The version of openpgp is 3.7.2

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