mogol / flutter_secure_storage

A Flutter plugin to store data in secure storage
https://pub.dartlang.org/packages/flutter_secure_storage
BSD 3-Clause "New" or "Revised" License
1.1k stars 344 forks source link

App built in release mode does not start #53

Closed novemberisms closed 2 years ago

novemberisms commented 5 years ago

My app built in release mode does not get past the launch screen. When built in debug mode, everything works fine.

In my main method, I have the following code that will check if a previous login session exists so the user does not need to log in again each time.

Future<null> main(List<String> args) async {
    // ...
    final storage = FlutterSecureStorage();
    final hasExisting = await storage.read(key: "isExisting");
    // ...
    runApp(MyApp(hasExisting: hasExisting));
}

And I can confirm that this plugin is the one causing the problem because when I change the code to the following

Future<null> main(List<String> args) async {
    // ...
    // final storage = FlutterSecureStorage();
    // final hasExisting = await storage.read(key: "isExisting");
    final hasExisting = false;
    // ...
    runApp(MyApp(hasExisting: hasExisting));
}

Everything works, but of course the desired function is not the same.

I can confirm it was working as of March 5, but it no longer does.

novemberisms commented 5 years ago

output of flutter doctor:

Kumetzs-iMac:edataquickinvoicecaptureapp kumetzproductions$ flutter doctor -v
[✓] Flutter (Channel stable, v1.5.4-hotfix.2, on Mac OS X 10.14.4 18E226, locale
    en-PH)
    • Flutter version 1.5.4-hotfix.2 at /Users/kumetzproductions/Dev/flutter
    • Framework revision 7a4c33425d (9 days ago), 2019-04-29 11:05:24 -0700
    • Engine revision 52c7a1e849
    • Dart version 2.3.0 (build 2.3.0-dev.0.5 a1668566e5)

[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at /Users/kumetzproductions/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling
      support)
    • Platform android-28, build-tools 28.0.3
    • Java binary at: /Applications/Android
      Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      1.8.0_152-release-1248-b01)
    • All Android licenses accepted.

[✓] iOS toolchain - develop for iOS devices (Xcode 10.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 10.2.1, Build version 10E1001
    • ios-deploy 1.9.4
    • CocoaPods version 1.6.1

[✓] Android Studio (version 3.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 33.3.1
    • Dart plugin version 182.5215
    • Java version OpenJDK Runtime Environment (build
      1.8.0_152-release-1248-b01)

[✓] VS Code (version 1.33.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.0.0

[✓] Connected device (1 available)
    • SM J415GN • d0ee681b • android-arm • Android 8.1.0 (API 27)

• No issues found!
novemberisms commented 5 years ago

more info: running flutter run --release starts the app and it gets stuck on the launch screen with the following output to the console:

E/flutter (27083): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: PlatformException(error, Unsupported value: javax.crypto.BadPaddingException: error:1e000065:Cipher functions:OPENSSL_internal:BAD_DECRYPT, null)
E/flutter (27083): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:564)
E/flutter (27083): #1      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:302)
E/flutter (27083): <asynchronous suspension>
E/flutter (27083): #2      FlutterSecureStorage.read (package:flutter_secure_storage/flutter_secure_storage.dart:16)
E/flutter (27083): <asynchronous suspension>
E/flutter (27083): #3      User.fetchExistingFromStorage (package:edataquick_invoice_capture/models/user.dart:144)
E/flutter (27083): <asynchronous suspension>
E/flutter (27083): #4      main (package:edataquick_invoice_capture/main.dart:23)
E/flutter (27083): <asynchronous suspension>
E/flutter (27083): #5      _runMainZoned.<anonymous closure>.<anonymous closure> (dart:ui/hooks.dart:197)
E/flutter (27083): #6      _rootRun (dart:async/zone.dart:1124)
E/flutter (27083): #7      _CustomZone.run (dart:async/zone.dart:1021)
E/flutter (27083): #8      _runZoned (dart:async/zone.dart:1516)
E/flutter (27083): #9      runZoned (dart:async/zone.dart:1500)
E/flutter (27083): #10     _runMainZoned.<anonymous closure> (dart:ui/hooks.dart:190)
E/flutter (27083): #11     _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:300)
E/flutter (27083): #12     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:171)
E/flutter (27083): 
EddieRietz commented 5 years ago

Same issue here, though I have a different output

E/FlutterSecureStoragePl(31921): Registration failed
E/FlutterSecureStoragePl(31921): java.lang.IllegalStateException: could not generate key in keystore
E/FlutterSecureStoragePl(31921):        at android.security.AndroidKeyPairGenerator.generateKeyPair(AndroidKeyPairGenerator.java:99)
E/FlutterSecureStoragePl(31921):        at java.security.KeyPairGenerator$KeyPairGeneratorImpl.generateKeyPair(KeyPairGenerator.java:276)
E/FlutterSecureStoragePl(31921):        at com.it_nomads.fluttersecurestorage.ciphers.RSACipher18Implementation.createKeys(RSACipher18Implementation.java:157)
E/FlutterSecureStoragePl(31921):        at com.it_nomads.fluttersecurestorage.ciphers.RSACipher18Implementation.createRSAKeysIfNeeded(RSACipher18Implementation.java:115)
E/FlutterSecureStoragePl(31921):        at com.it_nomads.fluttersecurestorage.ciphers.RSACipher18Implementation.<init>(RSACipher18Implementation.java:33)
E/FlutterSecureStoragePl(31921):        at com.it_nomads.fluttersecurestorage.ciphers.StorageCipher18Implementation.<init>(StorageCipher18Implementation.java:31)
E/FlutterSecureStoragePl(31921):        at com.it_nomads.fluttersecurestorage.FlutterSecureStoragePlugin.<init>(FlutterSecureStoragePlugin.java:46)
E/FlutterSecureStoragePl(31921):        at com.it_nomads.fluttersecurestorage.FlutterSecureStoragePlugin.registerWith(FlutterSecureStoragePlugin.java:33)
E/FlutterSecureStoragePl(31921):        at io.flutter.plugins.GeneratedPluginRegistrant.registerWith(GeneratedPluginRegistrant.java:30)
E/FlutterSecureStoragePl(31921):        at com.example.website.MainActivity.onCreate(MainActivity.java:11)
E/FlutterSecureStoragePl(31921):        at android.app.Activity.performCreate(Activity.java:6073)
E/FlutterSecureStoragePl(31921):        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1112)
E/FlutterSecureStoragePl(31921):        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2481)
E/FlutterSecureStoragePl(31921):        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2590)
E/FlutterSecureStoragePl(31921):        at android.app.ActivityThread.access$900(ActivityThread.java:162)
E/FlutterSecureStoragePl(31921):        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1453)
E/FlutterSecureStoragePl(31921):        at android.os.Handler.dispatchMessage(Handler.java:102)
E/FlutterSecureStoragePl(31921):        at android.os.Looper.loop(Looper.java:135)
E/FlutterSecureStoragePl(31921):        at android.app.ActivityThread.main(ActivityThread.java:5542)
E/FlutterSecureStoragePl(31921):        at java.lang.reflect.Method.invoke(Native Method)
E/FlutterSecureStoragePl(31921):        at java.lang.reflect.Method.invoke(Method.java:372)
E/FlutterSecureStoragePl(31921):        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:962)
E/FlutterSecureStoragePl(31921):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)
PankovSerge commented 5 years ago

Same here, don't work on any device (nexus 5 - 6.0.1, pixel 2 xl - 9.0.1, emulator with API 28

flutter doctor -v [✓] Flutter (Channel stable, v1.5.4-hotfix.2, on Mac OS X 10.12.6 16G1114, locale en-US) • Flutter version 1.5.4-hotfix.2 at /Users/ps/Library/flutter • Framework revision 7a4c33425d (2 weeks ago), 2019-04-29 11:05:24 -0700 • Engine revision 52c7a1e849 • Dart version 2.3.0 (build 2.3.0-dev.0.5 a1668566e5)

[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3) • Android SDK at /Users/ps/Library/Android/sdk • Android NDK location not configured (optional; useful for native profiling support) • Platform android-Q, build-tools 28.0.3 • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01) • All Android licenses accepted.

[✗] iOS toolchain - develop for iOS devices ✗ Xcode installation is incomplete; a full installation is necessary for iOS development. Download at: https://developer.apple.com/xcode/download/ Or install Xcode via the App Store. Once installed, run: sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer ✗ libimobiledevice and ideviceinstaller are not installed. To install with Brew, run: brew update brew install --HEAD usbmuxd brew link usbmuxd brew install --HEAD libimobiledevice brew install ideviceinstaller ✗ ios-deploy not installed. To install: brew install ios-deploy ✗ Brew can be used to install tools for iOS device development. Download brew at https://brew.sh/.

[!] Android Studio • Android Studio at /Applications/Android Studio 3.5 Preview.app/Contents ✗ Flutter plugin not installed; this adds Flutter specific functionality. ✗ Dart plugin not installed; this adds Dart specific functionality. • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b01)

[✓] Android Studio (version 3.4) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin version 35.3.1 • Dart plugin version 183.6270 • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)

[!] IntelliJ IDEA Community Edition (version 2017.3.4) • IntelliJ at /Applications/IntelliJ IDEA CE.app ✗ Flutter plugin not installed; this adds Flutter specific functionality. ✗ Dart plugin not installed; this adds Dart specific functionality. • For information about installing plugins, see https://flutter.dev/intellij-setup/#installing-the-plugins

[✓] VS Code (version 1.33.1) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.0.1

[✓] Connected device (1 available) • Android SDK built for x86 64 • emulator-5554 • android-x64 • Android 9 (API 28) (emulator)

chadkve commented 5 years ago

[ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: PlatformException(error, Unsupported value: javax.crypto.BadPaddingException: error:1e000065:Cipher functions:OPENSSL_internal:BAD_DECRYPT, null) E/flutter (27183): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:564) E/flutter (27183): #1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:302) E/flutter (27183): E/flutter (27183): #2 FlutterSecureStorage.read (package:flutter_secure_storage/flutter_secure_storage.dart:25) E/flutter (27183): E/flutter (27183): #3 _LoginScreenState.build. (package:medon/screens/login/screen.dart:55) E/flutter (27183): #4 _BlocListenerBaseState._subscribe. (package:flutter_bloc/src/bloc_listener.dart:115) E/flutter (27183): #5 _rootRunUnary (dart:async/zone.dart:1132) E/flutter (27183): #6 _CustomZone.runUnary (dart:async/zone.dart:1029) E/flutter (27183): #7 _CustomZone.runUnaryGuarded (dart:async/zone.dart:931) E/flutter (27183): #8 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336) E/flutter (27183): #9 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263) E/flutter (27183): #10 _SyncStreamController._sendData (dart:async/stream_controller.dart:764) E/flutter (27183): #11 _StreamController._add (dart:async/stream_controller.dart:640) E/flutter (27183): #12 _StreamController.add (dart:async/stream_controller.dart:586) E/flutter (27183): #13 _rootRunUnary (dart:async/zone.dart:1132) E/flutter (27183): #14 _CustomZone.runUnary (dart:async/zone.dart:1029) E/flutter (27183): #15 _CustomZone.runUnaryGuarded (dart:async/zone.dart:931) E/flutter (27183): #16 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336) E/flutter (27183): #17 _DelayedData.perform (dart:async/stream_impl.dart:591) E/flutter (27183): #18 _StreamImplEvents.handleNext (dart:async/stream_impl.dart:707) E/flutter (27183): #19 _PendingEvents.schedule. (dart:async/stream_impl.dart:667) E/flutter (27183): #20 _rootRun (dart:async/zone.dart:1120) E/flutter (27183): #21 _CustomZone.run (dart:async/zone.dart:1021) E/flutter (27183): #22 _CustomZone.runGuarded (dart:async/zone.dart:923) E/flutter (27183): #23 _CustomZone.bindCallbackGuarded. (dart:async/zone.dart:963) E/flutter (27183): #24 _rootRun (dart:async/zone.dart:1124) E/flutter (27183): #25 _CustomZone.run (dart:async/zone.dart:1021) E/flutter (27183): #26 _CustomZone.runGuarded (dart:async/zone.dart:923) E/flutter (27183): #27 _CustomZone.bindCallbackGuarded. (dart:async/zone.dart:963) E/flutter (27183): #28 _microtaskLoop (dart:async/schedule_microtask.dart:41) E/flutter (27183): #29 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50) E/flutter (27183):

pythoneer commented 5 years ago

Having the same Problem, but not only with release, also in "debug". One major thing i can remember is, that i updated the toolchain to (Android toolchain - develop for Android devices (Android SDK version 28.0.3) very recently and not much else.

Unhandled Exception: PlatformException(error, Unsupported value: javax.crypto.BadPaddingException: error:1e000065:Cipher functions:OPENSSL_internal:BAD_DECRYPT, null)
daniel-mf commented 5 years ago

I fixed this issue by executing await storage.deleteAll(); only once, after setting backups off:

<application
        ...
            android:allowBackup="false"
            android:fullBackupContent="false">
pythoneer commented 5 years ago

@daniel-mf at some point i added those attributes to the application tag but it was days after that the error occurred. Unfortunately the device which was affected (Nexus 6P) died a couple of days (bootloop). So is your suggestion to just make that call once after app installation or do you think this is triggered after a change to those attributes and i should call deleteAll in apps when i change this after those are initially released and/or don't bother if i started with those attributes in the first place. To be honest i can't really understand how those have any effect in regard to the problem. Do you have an idea?

daniel-mf commented 5 years ago

@pythoneer Sorry, I can't tell exactly what happened. I was getting the error, then I added the backup off attributes. Still same error. I thought that maybe the backup had already being done so I might need to delete it all. I executed deleteAll and it worked. Maybe something else happened, maybe unrelated, sorry. Perhaps you could try executing it every first time launch.

sccrgoalie1 commented 5 years ago

I was having the same problem as above. The easy fix for me was to clear storage for the app.

Settings -> Apps -> Your App -> Storage -> Clear Storage

pythoneer commented 5 years ago

What is still unclear to me is, if this is happening "in the wild" or has something to do with development. Because on one of my new devices i am developing on this was happening again. But i am unable to reproduce it. It just suddenly happened. But i can imagine it has something to do with rapid deployment where the app is starting and all of the sudden a new version is deployed right in between where something with the en/decryption is happening and some keys get only stored half way because the app is restarting/redeploying. It never occurred on devices that are there only for testing not developing.

One thing i do now is to make a "fake" call to the storage (read some useless key) at the start of the application and .deleteAll() if an exception is thrown. This would potentially delete all the user data, but it is better than the other way, because the app is unusable if this happens. We "just" store credentials inside it, that could easily be reentered – its just for convenience. But its still unfortunate because i don't know if our client plans to use it for something else in the future.

mogol commented 5 years ago

Do you see in logs this record?

                Log.e("StorageCipher18Impl", "unwrap key failed", e);
Henawey commented 3 years ago

this issue almost year and half old, I'm not sure if there is a plan to fix it soon

ATemirlan commented 3 years ago

Had the same issue. Fixed by adding TimeOutException. Inside LoginPage or in catch block delete all storage.

StatefulWidget homeScreen;

try {
    final token =
        await Application.getToken().timeout(const Duration(seconds: 2));
    homeScreen = token != null ? TabControllerPage() : LoginPage();
  } catch (e) {
    homeScreen = LoginPage();
  }

runApp(App(homeScreen));
karolinaoparczyk commented 3 years ago

I have a similar issue. After installing .apk file and launching application on a device, it uses FlutterSecureStorage to get information if user is logged in or not, along with other values. I expect null during first run, of course, but storage.read(key) seams to fail before returning any value.

Added backup tags in main/AndroidManifest.xml

<application
       ...
        android:allowBackup="false"
        android:fullBackupContent="false">

Added deleting keys on startup

final FlutterSecureStorage storage = FlutterSecureStorage();

Future<void> checkIfUserIsSignedIn() async {
    storage.deleteAll();

    try{
      isUserSignedIn = await storage.read(key: _isLoggedIn);
    }
    catch (e){
      print(e);
    }
    setState(() {});
  }

Tried with FlutterSecureStorage v.3.3.3 and FlutterSecureStorage v.3.2.0, but there was no change. I checked SDK version of my device (Honor 10) - 29. Also checked on other device (Samsung Galaxy S9+), but the issue also occurs.

Running flutter run --release causes warnings:

Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: C:\Users\karo\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_secure_storage-3.2.0\android\src\main\java\com\it_nomads\fluttersecurestorage\FlutterSecureStoragePlugin.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

and error:

Installing build\app\outputs\flutter-apk\app.apk...                376ms
Error: ADB exited with exit code 1
Performing Streamed Install

adb: failed to install C:\Users\karo\idom_mobile\build\app\outputs\flutter-apk\app.apk: Failure [INSTALL_FAILED_UPDATE_INCOMPATIBLE: Package com.project.idom signatures do not match previously installed version; ignoring!]
Uninstalling old version...
Installing build\app\outputs\flutter-apk\app.apk...                 6.9s

but successfully installs application on emulator and everything works as expected. The problem is when I install application on physical device. To generate .apk I use flutter build apk --release and install using app-release.apk file as stated in build log:

flutter build apk --release
You are building a fat APK that includes binaries for android-arm, android-arm64, android-x64.
If you are deploying the app to the Play Store, it's recommended to use app bundles or split the APK to reduce the APK size.
    To generate an app bundle, run:
        flutter build appbundle --target-platform android-arm,android-arm64,android-x64
        Learn more on: https://developer.android.com/guide/app-bundle
    To split the APKs per ABI, run:
        flutter build apk --target-platform android-arm,android-arm64,android-x64 --split-per-abi
        Learn more on:  https://developer.android.com/studio/build/configure-apk-splits#configure-abi-split
Running Gradle task 'assembleRelease'...
Running Gradle task 'assembleRelease'... Done                      69.9s
√ Built build\app\outputs\flutter-apk\app-release.apk (48.9MB).

My flutter doctor -v

flutter doctor -v
[√] Flutter (Channel dev, 1.24.0-10.2.pre, on Microsoft Windows [Version 10.0.18362.1198], locale en-GB)
    • Flutter version 1.24.0-10.2.pre at C:\Users\karo\flutter
    • Framework revision 022b333a08 (27 hours ago), 2020-11-18 11:35:09 -0800
    • Engine revision 07c1eed46b
    • Dart version 2.12.0 (build 2.12.0-29.10.beta)

[√] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    • Android SDK at C:\Users\karo\AppData\Local\Android\sdk
    • Platform android-30, build-tools 30.0.2
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    • All Android licenses accepted.

[√] Android Studio (version 4.1.0)
    • Android Studio at C:\Program Files\Android\Android Studio
    • 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 1.8.0_242-release-1644-b01)

[√] Connected device (1 available)
    • Android SDK built for x86 64 (mobile) • emulator-5554 • android-x64 • Android 10 (API 29) (emulator)

• No issues found!

I tried to make sure my project is migrated to AndroidX and got a message: No Usages Found in the Project.

I don't have any more ideas, could you help me?

karolinaoparczyk commented 3 years ago

I tried using SharedPreferencesas a temporary workaround, but it still didn't work - as I guess, the package was not initialized.

I built my app withflutter build apk --release --no-shrink after reading this thread https://github.com/flutter/flutter/issues/65334.

Then tried flutter build apk --release --no-shrink with the version of my application that uses FlutterSecureStorageand it worked.

Should I really consider it as a valid fix and always build my application this way?

abdulpiksi commented 3 years ago

may be this will help stackoverflow

LostInDarkMath commented 3 years ago

I have the same issue:


2021-06-13 16:34:48.764 7523-7566/? E/StorageCipher18Impl: unwrap key failed
    java.security.InvalidKeyException: Failed to unwrap key
        at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineUnwrap(AndroidKeyStoreCipherSpiBase.java:682)
        at javax.crypto.Cipher.unwrap(Cipher.java:2440)
        at c.c.a.b.a.a(Unknown Source:13)
        at c.c.a.b.b.<init>(Unknown Source:49)
        at c.c.a.a.b(Unknown Source:8)
        at c.c.a.a.a(Unknown Source:0)
        at c.c.a.a$b.run(Unknown Source:148)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:214)
        at android.os.HandlerThread.run(HandlerThread.java:67)
     Caused by: javax.crypto.IllegalBlockSizeException
        at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineDoFinal(AndroidKeyStoreCipherSpiBase.java:519)
        at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineUnwrap(AndroidKeyStoreCipherSpiBase.java:680)
        at javax.crypto.Cipher.unwrap(Cipher.java:2440) 
        at c.c.a.b.a.a(Unknown Source:13) 
        at c.c.a.b.b.<init>(Unknown Source:49) 
        at c.c.a.a.b(Unknown Source:8) 
        at c.c.a.a.a(Unknown Source:0) 
        at c.c.a.a$b.run(Unknown Source:148) 
        at android.os.Handler.handleCallback(Handler.java:883) 
        at android.os.Handler.dispatchMessage(Handler.java:100) 
        at android.os.Looper.loop(Looper.java:214) 
        at android.os.HandlerThread.run(HandlerThread.java:67) 
     Caused by: android.security.KeyStoreException: Unknown error
        at android.security.KeyStore.getKeyStoreException(KeyStore.java:1303)
        at android.security.keystore.KeyStoreCryptoOperationChunkedStreamer.doFinal(KeyStoreCryptoOperationChunkedStreamer.java:224)
        at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineDoFinal(AndroidKeyStoreCipherSpiBase.java:506)
        at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineUnwrap(AndroidKeyStoreCipherSpiBase.java:680) 
        at javax.crypto.Cipher.unwrap(Cipher.java:2440) 
        at c.c.a.b.a.a(Unknown Source:13) 
        at c.c.a.b.b.<init>(Unknown Source:49) 
        at c.c.a.a.b(Unknown Source:8) 
        at c.c.a.a.a(Unknown Source:0) 
        at c.c.a.a$b.run(Unknown Source:148) 
        at android.os.Handler.handleCallback(Handler.java:883) 
        at android.os.Handler.dispatchMessage(Handler.java:100) 
        at android.os.Looper.loop(Looper.java:214) 
        at android.os.HandlerThread.run(HandlerThread.java:67) 
2021-06-13 16:34:48.789 7523-7552/? E/flutter: [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: PlatformException(Exception encountered, read, javax.crypto.BadPaddingException: error:1e000065:Cipher functions:OPENSSL_internal:BAD_DECRYPT
        at com.android.org.conscrypt.NativeCrypto.EVP_CipherFinal_ex(Native Method)
        at com.android.org.conscrypt.OpenSSLCipher$EVP_CIPHER.doFinalInternal(OpenSSLCipher.java:602)
        at com.android.org.conscrypt.OpenSSLCipher.engineDoFinal(OpenSSLCipher.java:365)
        at javax.crypto.Cipher.doFinal(Cipher.java:2055)
        at c.c.a.b.b.b(Unknown Source:32)
        at c.c.a.a.b(Unknown Source:11)
        at c.c.a.a.d(Unknown Source:7)
        at c.c.a.a.a(Unknown Source:0)
        at c.c.a.a$b.run(Unknown Source:153)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:214)
        at android.os.HandlerThread.run(HandlerThread.java:67)
    , null)
    #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:597)
    #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:158)
    <asynchronous suspension>
    #2      FlutterSecureStorage.read (package:flutter_secure_storage/flutter_secure_storage.dart:50)
    <asynchronous suspension>
    #3      SecureStorage.readPassword (package:foo/services/secure_storage.dart:33)
    <asynchronous suspension>
    #4      SecureStorage.loadCredentialsAndCreateEmptyUser (package:foo/services/secure_storage.dart:27)
    <asynchronous suspension>
    #5      Controller.getInstance (package:foo/controller/controller.dart:116)
    <asynchronous suspension>
    #6      main (package:foo/main.dart:25)
    <asynchronous suspension>
juliansteenbakker commented 2 years ago

Can everyone that is having this issue make sure they are using embedding v2 on their application. Also please comment the output of flutter doctor -v and make sure that you are using the latest version of this plugin, v4.2.1.

juliansteenbakker commented 2 years ago

I'm closing this for now due to no activity. If anyone still has this issue, feel free to comment.

feduke-nukem commented 2 years ago

@juliansteenbakker I am also facing problem of PlatformException when I am downloading installing aab from market. Yes, the clear storage do the thing, but that's incorrect behavior. Huawei Mate 20 light.

GeylanKalafMohe commented 10 months ago

Still facing this issue:

PlatformException(Exception encountered, write, java.lang.NullPointerException: Attempt to invoke interface method 'byte[] q3.i.a(byte[])' on a null object reference at p3.a.m(Unknown Source:24) at p3.e$b.run(Unknown Source:267) at android.os.Handler.handleCallback(Handler.java:938) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:223) at android.os.HandlerThread.run(HandlerThread.java:67) , null)

Device Brand:Motorola Model:Lenovo K14 Plus Orientation:Portrait

Operating System Version:Android 11 Orientation:Portrait Rooted:No

jhj0517 commented 6 months ago

faced issue with :

E/flutter (28504): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(Exception encountered, read, jav
ax.crypto.BadPaddingException: error:1e000065:Cipher functions:OPENSSL_internal:BAD_DECRYPT

on Android 13 when building the app in release mode. Fixed by adding it to the manifest.

<application
        ...
            android:allowBackup="false"
            android:fullBackupContent="false">
harSofja commented 2 weeks ago

I have been receiving this error as well:

PlatformException (Exception encountered, write, java.lang.NullPointerException: Attempt to invoke interface method 'byte[] a5.i.a (bytel]) on a null object reference at z4.a.p (Unknown Source:24) at z4.e$b.run (Unknown Source:278) at android.os.Handler.handleCallback(Handler.java:969) at android.os.Handler.dispatchMessage(Handler.java:100) at android.os.Looper.loopOnce(Looper.java:201) at android.os.Looper.loop(Looper.java:288) at android.os.HandlerThread.run (HandlerThread.java:67) , null) 1

I have not being able to figure out what it is. Our app is already live and this only occurs for a specific android tablet called 'Blackview Tab 30 WiFi'. Last time I faced something similar called 'BadPaddingException' it was again on a specific android tablet. In general I have not being able to reproduce this error on any other physical device or emulators. We had managed to fix the BadPaddingException by telling the customer to do a factory reset and it worked. This is not ideal I know. Note that we did the same to this guy with the Blackview tablet but this did not fix it this time. The error happened during login phase in both cases.

I haven't been able to find much on the issue, right now I am just trying to add null checks everywhere during login phase. I am a junior dev.