pinkeshdarji / endtoendencryption

10 stars 3 forks source link

Error: error:1e000065:Cipher functions:OPENSSL_internal:BAD_DECRYPT #1

Open nizarmasri opened 2 years ago

nizarmasri commented 2 years ago

Encryption is working fine, I'm able to see the encrypted messages on the Stream Explorer, but when it comes to decryption, I'm getting this error message:

Error: error:1e000065:Cipher functions:OPENSSL_internal:BAD_DECRYPT

I'm using a channel with two users on Stream. My main.dart creates the client and generates the keys but does not connect to a user yet, that is done after the login screen.

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();

  /* SharedPreferences prefs = await SharedPreferences.getInstance();
  await prefs.clear();*/

  final client = StreamChatClient(
    'key',
    logLevel: Level.INFO,
  );

  await AppE2EE().generateKeys();

  runApp(
    MyApp(
      client: client,
    ),
  );
}

This is the login function to connect a user:

Future<void> connectClient(DemoUser user) async {
    setState(() {
      _loading = true;
    });
    try {
      await AppE2EE().generateKeys();
      /*Map<String, dynamic> publicKeyJwk =
          await AppE2EE().keyPair.publicKey.exportJsonWebKey();*/

      await StreamChat.of(context).client.connectUser(
          User(
            id: user.id,
            extraData: {
              'name': user.name,
              'image': user.image,
              //'publicKey': publicKeyJwk,
            },
          ),
          user.token);

      Navigator.of(context).pushReplacement(
        MaterialPageRoute(
            builder: (_) => HomeScreen()),
      );
    } on Exception catch (e, st) {
      logger.e('Could not connect user', e, st);
      setState(() {
        _loading = false;
      });
    }
  }

There are two await AppE2EE().generateKeys() here, but I've tried one each and still the same error. I've tried re-installing the app, using a new channel, running on a physical device, and cleaning the shared preferences when the app starts await prefs.clear(). My app_e2ee.dart is the same and so is everything aside from the login.

Screenshot_1655549462

Not sure if this repo is still active but it'd be great :)

flutter doctor -v

[✓] Flutter (Channel stable, 3.0.1, on macOS 11.6 20G165 darwin-arm, locale en-BR)
    • Flutter version 3.0.1 at /Users/user/Downloads/flutter 2
    • Upstream repository git@github.com:flutter/flutter.git
    • Framework revision fb57da5f94 (4 weeks ago), 2022-05-19 15:50:29 -0700
    • Engine revision caaafc5604
    • Dart version 2.17.1
    • DevTools version 2.12.2

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/nizarmasri/Library/Android/sdk
    • Platform android-31, build-tools 31.0.0
    • ANDROID_SDK_ROOT = /opt/homebrew/Caskroom/android-commandlinetools
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)

[✓] VS Code (version 1.67.2)
    • VS Code at /Users/nizarmasri/Downloads/VSCode-darwin-arm64/Visual Studio Code.app/Contents
    • Flutter extension can be installed from:
      🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (4 available)
    • M2101K6P (mobile)           • 55e3224       • android-arm64  • Android 12 (API 31)
    • sdk gphone64 arm64 (mobile) • emulator-5554 • android-arm64  • Android 12 (API 31) (emulator)
    • macOS (desktop)             • macos         • darwin-arm64   • macOS 11.6 20G165 darwin-arm
    • Chrome (web)                • chrome        • web-javascript • Google Chrome 101.0.4951.64

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!
debjeetproso commented 1 year ago

did you find the solution for this ?