Skip to content

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

Open
@itlwy

Description

@itlwy

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions