Comments (19)
As I Understand the issue:
Data is stored encrypted in shared prefs. Private key to decrypt the key — in keystore.
Shared prefs are restored from backup, but keystore isn’t. So it’s technically impossible to decrypt data , if the key is lost.
Another way to handle this — throw exception and let the app delete old data.
from flutter_secure_storage.
I know this issue is closed but after reading both the read.me and this issue it's not clear to me if my intended use case will work with this package;
Goal
- Store encrypted items in the keychain so that IF the user loses their device they can access these items on a new device
Disabling automatic backup would clearly not be a good idea in this case.
from flutter_secure_storage.
This still happens on v3.1.2 and only in release mode
@ernestomar workaround worked for me. Setting android:allowBackup="false"
application attribute on android/app/src/main/AndroidManifest.xml
.
09-26 11:05:24.584 26696-26696/? E/StorageCipher18Impl: unwrap key failed
java.security.InvalidKeyException: Failed to unwrap key
at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineUnwrap(AndroidKeyStoreCipherSpiBase.java:618)
at javax.crypto.Cipher.unwrap(Cipher.java:1707)
at com.it_nomads.fluttersecurestorage.ciphers.RSACipher18Implementation.unwrap(RSACipher18Implementation.java:46)
at com.it_nomads.fluttersecurestorage.ciphers.StorageCipher18Implementation.<init>(StorageCipher18Implementation.java:44)
at com.it_nomads.fluttersecurestorage.FlutterSecureStoragePlugin.<init>(FlutterSecureStoragePlugin.java:46)
at com.it_nomads.fluttersecurestorage.FlutterSecureStoragePlugin.registerWith(FlutterSecureStoragePlugin.java:33)
at io.flutter.plugins.GeneratedPluginRegistrant.registerWith(GeneratedPluginRegistrant.java:20)
at com.xxxx.xxxxxx.MainActivity.onCreate(MainActivity.java:12)
at android.app.Activity.performCreate(Activity.java:6259)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2382)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1357)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5459)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
Caused by: javax.crypto.IllegalBlockSizeException
at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineDoFinal(AndroidKeyStoreCipherSpiBase.java:486)
at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineUnwrap(AndroidKeyStoreCipherSpiBase.java:616)
at javax.crypto.Cipher.unwrap(Cipher.java:1707)
at com.it_nomads.fluttersecurestorage.ciphers.RSACipher18Implementation.unwrap(RSACipher18Implementation.java:46)
at com.it_nomads.fluttersecurestorage.ciphers.StorageCipher18Implementation.<init>(StorageCipher18Implementation.java:44)
at com.it_nomads.fluttersecurestorage.FlutterSecureStoragePlugin.<init>(FlutterSecureStoragePlugin.java:46)
at com.it_nomads.fluttersecurestorage.FlutterSecureStoragePlugin.registerWith(FlutterSecureStoragePlugin.java:33)
at io.flutter.plugins.GeneratedPluginRegistrant.registerWith(GeneratedPluginRegistrant.java:20)
at com.xxxx.xxxxxx.MainActivity.onCreate(MainActivity.java:12)
at android.app.Activity.performCreate(Activity.java:6259)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2382)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1357)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5459)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
Caused by: android.security.KeyStoreException: Unknown error
at android.security.KeyStore.getKeyStoreException(KeyStore.java:632)
at android.security.keystore.KeyStoreCryptoOperationChunkedStreamer.doFinal(KeyStoreCryptoOperationChunkedStreamer.java:224)
at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineDoFinal(AndroidKeyStoreCipherSpiBase.java:473)
at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineUnwrap(AndroidKeyStoreCipherSpiBase.java:616)
at javax.crypto.Cipher.unwrap(Cipher.java:1707)
at com.it_nomads.fluttersecurestorage.ciphers.RSACipher18Implementation.unwrap(RSACipher18Implementation.java:46)
at com.it_nomads.fluttersecurestorage.ciphers.StorageCipher18Implementation.<init>(StorageCipher18Implementation.java:44)
at com.it_nomads.fluttersecurestorage.FlutterSecureStoragePlugin.<init>(FlutterSecureStoragePlugin.java:46)
at com.it_nomads.fluttersecurestorage.FlutterSecureStoragePlugin.registerWith(FlutterSecureStoragePlugin.java:33)
at io.flutter.plugins.GeneratedPluginRegistrant.registerWith(GeneratedPluginRegistrant.java:20)
at com.xxxx.xxxxxx.MainActivity.onCreate(MainActivity.java:12)
at android.app.Activity.performCreate(Activity.java:6259)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2382)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1357)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5459)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel beta, v0.7.3, on Linux, locale en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK 27.0.3)
[✓] Android Studio (version 3.2)
[✓] Connected devices (1 available)
• No issues found!
from flutter_secure_storage.
Ok thanks for the clarification.
Catching the exception and then deleting shared prefs data is exactly what we implemented atm.
from flutter_secure_storage.
Disabling the backup for android will prevent the crash, but I was wondering if there is a more suitable approach we can take for when we want to keep the 'allow backup' option for Android enabled while also using this plugin?
from flutter_secure_storage.
As I Understand the issue:
Data is stored encrypted in shared prefs. Private key to decrypt the key — in keystore.
Shared prefs are restored from backup, but keystore isn’t. So it’s technically impossible to decrypt data , if the key is lost.
Another way to handle this — throw exception and let the app delete old data.
Lol, how dare I call myself a developer.
from flutter_secure_storage.
@geeky-dawood How did you able to solve it, only by disabling backup?
from flutter_secure_storage.
Seeing the same when switching between profile and release builds.
Built build/app/outputs/apk/profile/app-profile.apk (13.2MB).
Installing build/app/outputs/apk/app.apk...
W/KeyStore(32540): KeyStore exception
W/KeyStore(32540): android.os.ServiceSpecificException: (code 7)
W/KeyStore(32540): at android.os.Parcel.createException(Parcel.java:1956)
W/KeyStore(32540): at android.os.Parcel.readException(Parcel.java:1910)
W/KeyStore(32540): at android.os.Parcel.readException(Parcel.java:1860)
W/KeyStore(32540): at android.security.IKeystoreService$Stub$Proxy.get(IKeystoreService.java:786)
W/KeyStore(32540): at android.security.KeyStore.get(KeyStore.java:195)
W/KeyStore(32540): at android.security.keystore.AndroidKeyStoreSpi.engineGetCertificateChain(AndroidKeyStoreSpi.java:118)
W/KeyStore(32540): at java.security.KeyStoreSpi.engineGetEntry(KeyStoreSpi.java:484)
W/KeyStore(32540): at java.security.KeyStore.getEntry(KeyStore.java:1560)
W/KeyStore(32540): at com.it_nomads.fluttersecurestorage.ciphers.RSACipher18Implementation.getEntry(RSACipher18Implementation.java:69)
W/KeyStore(32540): at com.it_nomads.fluttersecurestorage.ciphers.RSACipher18Implementation.unwrap(RSACipher18Implementation.java:42)
W/KeyStore(32540): at com.it_nomads.fluttersecurestorage.ciphers.StorageCipher18Implementation.<init>(StorageCipher18Implementation.java:48)
W/KeyStore(32540): at com.it_nomads.fluttersecurestorage.FlutterSecureStoragePlugin.<init>(FlutterSecureStoragePlugin.java:46)
W/KeyStore(32540): at com.it_nomads.fluttersecurestorage.FlutterSecureStoragePlugin.registerWith(FlutterSecureStoragePlugin.java:33)
W/KeyStore(32540): at io.flutter.plugins.GeneratedPluginRegistrant.registerWith(GeneratedPluginRegistrant.java:26)
W/KeyStore(32540): at io.ottomatic.odailies.MainActivity.onCreate(MainActivity.java:12)
W/KeyStore(32540): at android.app.Activity.performCreate(Activity.java:7136)
W/KeyStore(32540): at android.app.Activity.performCreate(Activity.java:7127)
W/KeyStore(32540): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
W/KeyStore(32540): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
W/KeyStore(32540): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
W/KeyStore(32540): at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
W/KeyStore(32540): at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
W/KeyStore(32540): at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
W/KeyStore(32540): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
W/KeyStore(32540): at android.os.Handler.dispatchMessage(Handler.java:106)
W/KeyStore(32540): at android.os.Looper.loop(Looper.java:193)
W/KeyStore(32540): at android.app.ActivityThread.main(ActivityThread.java:6669)
W/KeyStore(32540): at java.lang.reflect.Method.invoke(Native Method)
W/KeyStore(32540): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
W/KeyStore(32540): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
E/FlutterSecureStoragePl(32540): Registration failed
E/FlutterSecureStoragePl(32540): java.security.InvalidKeyException: Failed to unwrap key
E/FlutterSecureStoragePl(32540): at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineUnwrap(AndroidKeyStoreCipherSpiBase.java:682)
E/FlutterSecureStoragePl(32540): at javax.crypto.Cipher.unwrap(Cipher.java:2440)
E/FlutterSecureStoragePl(32540): at com.it_nomads.fluttersecurestorage.ciphers.RSACipher18Implementation.unwrap(RSACipher18Implementation.java:46)
E/FlutterSecureStoragePl(32540): at com.it_nomads.fluttersecurestorage.ciphers.StorageCipher18Implementation.<init>(StorageCipher18Implementation.java:48)
E/FlutterSecureStoragePl(32540): at com.it_nomads.fluttersecurestorage.FlutterSecureStoragePlugin.<init>(FlutterSecureStoragePlugin.java:46)
E/FlutterSecureStoragePl(32540): at com.it_nomads.fluttersecurestorage.FlutterSecureStoragePlugin.registerWith(FlutterSecureStoragePlugin.java:33)
E/FlutterSecureStoragePl(32540): at io.flutter.plugins.GeneratedPluginRegistrant.registerWith(GeneratedPluginRegistrant.java:26)
E/FlutterSecureStoragePl(32540): at io.ottomatic.odailies.MainActivity.onCreate(MainActivity.java:12)
E/FlutterSecureStoragePl(32540): at android.app.Activity.performCreate(Activity.java:7136)
E/FlutterSecureStoragePl(32540): at android.app.Activity.performCreate(Activity.java:7127)
E/FlutterSecureStoragePl(32540): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
E/FlutterSecureStoragePl(32540): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
E/FlutterSecureStoragePl(32540): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
E/FlutterSecureStoragePl(32540): at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
E/FlutterSecureStoragePl(32540): at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
E/FlutterSecureStoragePl(32540): at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
E/FlutterSecureStoragePl(32540): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
E/FlutterSecureStoragePl(32540): at android.os.Handler.dispatchMessage(Handler.java:106)
E/FlutterSecureStoragePl(32540): at android.os.Looper.loop(Looper.java:193)
E/FlutterSecureStoragePl(32540): at android.app.ActivityThread.main(ActivityThread.java:6669)
E/FlutterSecureStoragePl(32540): at java.lang.reflect.Method.invoke(Native Method)
E/FlutterSecureStoragePl(32540): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
E/FlutterSecureStoragePl(32540): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
E/FlutterSecureStoragePl(32540): Caused by: javax.crypto.IllegalBlockSizeException
E/FlutterSecureStoragePl(32540): at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineDoFinal(AndroidKeyStoreCipherSpiBase.java:519)
E/FlutterSecureStoragePl(32540): at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineUnwrap(AndroidKeyStoreCipherSpiBase.java:680)
E/FlutterSecureStoragePl(32540): ... 22 more
E/FlutterSecureStoragePl(32540): Caused by: android.security.KeyStoreException: Unknown error
E/FlutterSecureStoragePl(32540): at android.security.KeyStore.getKeyStoreException(KeyStore.java:839)
E/FlutterSecureStoragePl(32540): at android.security.keystore.KeyStoreCryptoOperationChunkedStreamer.doFinal(KeyStoreCryptoOperationChunkedStreamer.java:224)
E/FlutterSecureStoragePl(32540): at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineDoFinal(AndroidKeyStoreCipherSpiBase.java:506)
E/FlutterSecureStoragePl(32540): ... 23 more
I/FlutterActivityDelegate(32540): onResume setting current activity to this
I/OpenGLRenderer(32540): Initialized EGL, version 1.4
D/OpenGLRenderer(32540): Swap behavior 1
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel beta, v0.5.1, on Mac OS X 10.14 18A353d, locale de-CH)
[✓] Android toolchain - develop for Android devices (Android SDK 27.0.3)
[✓] iOS toolchain - develop for iOS devices (Xcode 10.0)
[✓] Android Studio (version 3.1)
[✓] Connected devices (2 available)
• No issues found!
from flutter_secure_storage.
Same issue here... works fine when installing locally via ADB, but fails when installing from Play store Alpha.
java.security.InvalidKeyException: Failed to unwrap key
at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineUnwrap(AndroidKeyStoreCipherSpiBase.java:682)
at javax.crypto.Cipher.unwrap(Cipher.java:2126)
at a.b.a.a.a.a(Unknown Source:17)
at a.b.a.a.c.<init>(Unknown Source:86)
at a.b.a.a.<init>(Unknown Source:27)
at a.b.a.a.a(Unknown Source:6)
at io.flutter.plugins.GeneratedPluginRegistrant.registerWith(Unknown Source:13)```
from flutter_secure_storage.
I found a workaround:
The issue was throw because Android application has backups on Google Drive enabled. After disable it in the application with:
android:allowBackup="true"
It works again..
(More info on https://developer.android.com/guide/topics/data/autobackup#EnablingAutoBackup )
ORIGINAL POST
Same issue here with 3.1.1 package version . I pulled modification fro git and then the error raised.
Right now I can't run the project. This is my output
Launching lib/main.dart on Redmi Note 5 in debug mode...
Built build/app/outputs/apk/debug/app-debug.apk.
E/FlutterSecureStoragePl(24032): Registration failed
E/FlutterSecureStoragePl(24032): java.security.InvalidKeyException: Failed to unwrap key
E/FlutterSecureStoragePl(24032): at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineUnwrap(AndroidKeyStoreCipherSpiBase.java:682)
E/FlutterSecureStoragePl(24032): at javax.crypto.Cipher.unwrap(Cipher.java:2126)
E/FlutterSecureStoragePl(24032): at com.it_nomads.fluttersecurestorage.ciphers.RSACipher18Implementation.unwrap(RSACipher18Implementation.java:46)
E/FlutterSecureStoragePl(24032): at com.it_nomads.fluttersecurestorage.ciphers.StorageCipher18Implementation.<init>(StorageCipher18Implementation.java:48)
E/FlutterSecureStoragePl(24032): at com.it_nomads.fluttersecurestorage.FlutterSecureStoragePlugin.<init>(FlutterSecureStoragePlugin.java:46)
E/FlutterSecureStoragePl(24032): at com.it_nomads.fluttersecurestorage.FlutterSecureStoragePlugin.registerWith(FlutterSecureStoragePlugin.java:33)
E/FlutterSecureStoragePl(24032): at io.flutter.plugins.GeneratedPluginRegistrant.registerWith(GeneratedPluginRegistrant.java:18)
E/FlutterSecureStoragePl(24032): at net.it.cirrus.pocketbank.MainActivity.onCreate(MainActivity.java:15)
E/FlutterSecureStoragePl(24032): at android.app.Activity.performCreate(Activity.java:7087)
E/FlutterSecureStoragePl(24032): at android.app.Activity.performCreate(Activity.java:7078)
E/FlutterSecureStoragePl(24032): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1215)
E/FlutterSecureStoragePl(24032): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2763)
E/FlutterSecureStoragePl(24032): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2888)
E/FlutterSecureStoragePl(24032): at android.app.ActivityThread.-wrap11(Unknown Source:0)
E/FlutterSecureStoragePl(24032): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1609)
E/FlutterSecureStoragePl(24032): at android.os.Handler.dispatchMessage(Handler.java:106)
E/FlutterSecureStoragePl(24032): at android.os.Looper.loop(Looper.java:171)
E/FlutterSecureStoragePl(24032): at android.app.ActivityThread.main(ActivityThread.java:6606)
E/FlutterSecureStoragePl(24032): at java.lang.reflect.Method.invoke(Native Method)
E/FlutterSecureStoragePl(24032): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:518)
E/FlutterSecureStoragePl(24032): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
E/FlutterSecureStoragePl(24032): Caused by: javax.crypto.IllegalBlockSizeException
E/FlutterSecureStoragePl(24032): at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineDoFinal(AndroidKeyStoreCipherSpiBase.java:519)
E/FlutterSecureStoragePl(24032): at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineUnwrap(AndroidKeyStoreCipherSpiBase.java:680)
E/FlutterSecureStoragePl(24032): ... 20 more
E/FlutterSecureStoragePl(24032): Caused by: android.security.KeyStoreException: Unknown error
E/FlutterSecureStoragePl(24032): at android.security.KeyStore.getKeyStoreException(KeyStore.java:697)
E/FlutterSecureStoragePl(24032): at android.security.keystore.KeyStoreCryptoOperationChunkedStreamer.doFinal(KeyStoreCryptoOperationChunkedStreamer.java:224)
E/FlutterSecureStoragePl(24032): at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineDoFinal(AndroidKeyStoreCipherSpiBase.java:506)
E/FlutterSecureStoragePl(24032): ... 21 more
D/OpenGLRenderer(24032): HWUI GL Pipeline
What I'v tried:
- Drop App on phone and then run again with USB cable. DON'T WORK
- Reinstall packages. DON'T WORK
flutter pub pub cache repair - Clean project. DON'T WORK
flutter clean project - Drop App on phone -> Clean project -> Donwngrade to 3.1.0 DON'T WORK. Stacktrace:
Launching lib/main.dart on Redmi Note 5 in debug mode...
Note: /Users/ecampohermoso/opt/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_secure_storage-3.1.0/android/src/main/java/com/it_nomads/fluttersecurestorage/FlutterSecureStoragePlugin.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Built build/app/outputs/apk/debug/app-debug.apk.
E/FlutterSecureStoragePl( 7252): Registration failed
E/FlutterSecureStoragePl( 7252): java.security.InvalidKeyException: Failed to unwrap key
E/FlutterSecureStoragePl( 7252): at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineUnwrap(AndroidKeyStoreCipherSpiBase.java:682)
E/FlutterSecureStoragePl( 7252): at javax.crypto.Cipher.unwrap(Cipher.java:2126)
E/FlutterSecureStoragePl( 7252): at com.it_nomads.fluttersecurestorage.ciphers.RSACipher18Implementation.unwrap(RSACipher18Implementation.java:46)
E/FlutterSecureStoragePl( 7252): at com.it_nomads.fluttersecurestorage.ciphers.StorageCipher18Implementation.<init>(StorageCipher18Implementation.java:48)
E/FlutterSecureStoragePl( 7252): at com.it_nomads.fluttersecurestorage.FlutterSecureStoragePlugin.<init>(FlutterSecureStoragePlugin.java:46)
E/FlutterSecureStoragePl( 7252): at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineDoFinal(AndroidKeyStoreCipherSpiBase.java:519)
E/FlutterSecureStoragePl( 7252): at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineUnwrap(AndroidKeyStoreCipherSpiBase.java:680)
E/FlutterSecureStoragePl( 7252): ... 20 more
E/FlutterSecureStoragePl( 7252): Caused by: android.security.KeyStoreException: Unknown error
E/FlutterSecureStoragePl( 7252): at android.security.KeyStore.getKeyStoreException(KeyStore.java:697)
E/FlutterSecureStoragePl( 7252): at android.security.keystore.KeyStoreCryptoOperationChunkedStreamer.doFinal(KeyStoreCryptoOperationChunkedStreamer.java:224)
E/FlutterSecureStoragePl( 7252): at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineDoFinal(AndroidKeyStoreCipherSpiBase.java:506)
E/FlutterSecureStoragePl( 7252): ... 21 more
D/OpenGLRenderer( 7252): HWUI GL Pipeline
I/OpenGLRenderer( 7252): Initialized EGL, version 1.4
D/OpenGLRenderer( 7252): Swap behavior 2
Application finished.
- Drop App on phone -> Clean project -> Donwngrade to 3.0.0 DON'T WORK. Error when try to read from secure_storage. Stacktrace:
E/MethodChannel#plugins.it_nomads.com/flutter_secure_storage(18212): Failed to handle method call
E/MethodChannel#plugins.it_nomads.com/flutter_secure_storage(18212): java.lang.IllegalArgumentException: Unsupported value: javax.crypto.BadPaddingException: error:1e000065:Cipher functions:OPENSSL_internal:BAD_DECRYPT
E/MethodChannel#plugins.it_nomads.com/flutter_secure_storage(18212): at io.flutter.plugin.common.StandardMessageCodec.writeValue(StandardMessageCodec.java:293)
E/MethodChannel#plugins.it_nomads.com/flutter_secure_storage(18212): at io.flutter.plugin.common.StandardMethodCodec.encodeErrorEnvelope(StandardMethodCodec.java:70)
E/MethodChannel#plugins.it_nomads.com/flutter_secure_storage(18212): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.error(MethodChannel.java:199)
E/MethodChannel#plugins.it_nomads.com/flutter_secure_storage(18212): at com.it_nomads.fluttersecurestorage.FlutterSecureStoragePlugin.onMethodCall(FlutterSecureStoragePlugin.java:75)
E/MethodChannel#plugins.it_nomads.com/flutter_secure_storage(18212): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:191)
E/MethodChannel#plugins.it_nomads.com/flutter_secure_storage(18212): at io.flutter.view.FlutterNativeView.handlePlatformMessage(FlutterNativeView.java:163)
E/MethodChannel#plugins.it_nomads.com/flutter_secure_storage(18212): at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#plugins.it_nomads.com/flutter_secure_storage(18212): at android.os.MessageQueue.next(MessageQueue.java:331)
E/MethodChannel#plugins.it_nomads.com/flutter_secure_storage(18212): at android.os.Looper.loop(Looper.java:147)
E/MethodChannel#plugins.it_nomads.com/flutter_secure_storage(18212): at android.app.ActivityThread.main(ActivityThread.java:6606)
E/MethodChannel#plugins.it_nomads.com/flutter_secure_storage(18212): at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#plugins.it_nomads.com/flutter_secure_storage(18212): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:518)
E/MethodChannel#plugins.it_nomads.com/flutter_secure_storage(18212): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
I/zygote64(18212): Background concurrent copying GC freed 4080(250KB) AllocSpace objects, 2(104KB) LOS objects, 55% free, 1219KB/2MB, paused 5.299ms total 108.261ms
W/IInputConnectionWrapper(18212): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper(18212): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper(18212): getTextAfterCursor on inactive InputConnection
- Drop Project -> clone Project -> flutter run. DON'T WORK. Exception:
Syncing files to device Redmi Note 5...
E/FlutterSecureStoragePl(26649): Registration failed
E/FlutterSecureStoragePl(26649): java.security.InvalidKeyException: Failed to unwrap key
E/FlutterSecureStoragePl(26649): at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineUnwrap(AndroidKeyStoreCipherSpiBase.java:682)
E/FlutterSecureStoragePl(26649): at javax.crypto.Cipher.unwrap(Cipher.java:2126)
E/FlutterSecureStoragePl(26649): at com.it_nomads.fluttersecurestorage.ciphers.RSACipher18Implementation.unwrap(RSACipher18Implementation.java:46)
E/FlutterSecureStoragePl(26649): at com.it_nomads.fluttersecurestorage.ciphers.StorageCipher18Implementation.<init>(StorageCipher18Implementation.java:48)
E/FlutterSecureStoragePl(26649): at com.it_nomads.fluttersecurestorage.FlutterSecureStoragePlugin.<init>(FlutterSecureStoragePlugin.java:46)
E/FlutterSecureStoragePl(26649): at com.it_nomads.fluttersecurestorage.FlutterSecureStoragePlugin.registerWith(FlutterSecureStoragePlugin.java:33)
E/FlutterSecureStoragePl(26649): at io.flutter.plugins.GeneratedPluginRegistrant.registerWith(GeneratedPluginRegistrant.java:18)
E/FlutterSecureStoragePl(26649): at net.it.cirrus.pocketbank.MainActivity.onCreate(MainActivity.java:15)
E/FlutterSecureStoragePl(26649): at android.app.Activity.performCreate(Activity.java:7087)
E/FlutterSecureStoragePl(26649): at android.app.Activity.performCreate(Activity.java:7078)
E/FlutterSecureStoragePl(26649): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1215)
E/FlutterSecureStoragePl(26649): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2763)
E/FlutterSecureStoragePl(26649): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2888)
E/FlutterSecureStoragePl(26649): at android.app.ActivityThread.-wrap11(Unknown Source:0)
E/FlutterSecureStoragePl(26649): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1609)
E/FlutterSecureStoragePl(26649): at android.os.Handler.dispatchMessage(Handler.java:106)
E/FlutterSecureStoragePl(26649): at android.os.Looper.loop(Looper.java:171)
E/FlutterSecureStoragePl(26649): at android.app.ActivityThread.main(ActivityThread.java:6606)
E/FlutterSecureStoragePl(26649): at java.lang.reflect.Method.invoke(Native Method)
E/FlutterSecureStoragePl(26649): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:518)
E/FlutterSecureStoragePl(26649): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
E/FlutterSecureStoragePl(26649): Caused by: javax.crypto.IllegalBlockSizeException
E/FlutterSecureStoragePl(26649): at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineDoFinal(AndroidKeyStoreCipherSpiBase.java:519)
E/FlutterSecureStoragePl(26649): at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineUnwrap(AndroidKeyStoreCipherSpiBase.java:680)
E/FlutterSecureStoragePl(26649): ... 20 more
E/FlutterSecureStoragePl(26649): Caused by: android.security.KeyStoreException: Unknown error
E/FlutterSecureStoragePl(26649): at android.security.KeyStore.getKeyStoreException(KeyStore.java:697)
E/FlutterSecureStoragePl(26649): at android.security.keystore.KeyStoreCryptoOperationChunkedStreamer.doFinal(KeyStoreCryptoOperationChunkedStreamer.java:224)
E/FlutterSecureStoragePl(26649): at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineDoFinal(AndroidKeyStoreCipherSpiBase.java:506)
E/FlutterSecureStoragePl(26649): ... 21 more
D/OpenGLRenderer(26649): HWUI GL Pipeline
I/flutter (26649): MissingPluginException(No implementation found for method read on channel plugins.it_nomads.com/flutter_secure_storage)
I/flutter (26649): #0 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:278:7)
I/flutter (26649): <asynchronous suspension>
I/flutter (26649): #1 FlutterSecureStorage.read (package:flutter_secure_storage/flutter_secure_storage.dart:16:24)
I/flutter (26649): <asynchronous suspension>
I/flutter (26649): #2 SecureStorage.read (file:///Users/ecampohermoso/data/pocketX/front-mobile/lib/helpers/secure_storage.dart:16:36)
I/flutter (26649): <asynchronous suspension>
I/flutter (26649): #3 _AffiliationPage.initState.<anonymous closure> (file:///Users/ecampohermoso/data/pocketX/front-mobile/lib/pages/affiliation.dart:60:23)
I/flutter (26649): #4 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:990:15)
I/flutter (26649): #5 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:938:9)
I/flutter (26649): #6 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/scheduler/b
I/OpenGLRenderer(26649): Initialized EGL, version 1.4
D/OpenGLRenderer(26649): Swap behavior 2Syncing files to device Redmi Note 5...
E/FlutterSecureStoragePl(26649): Registration failed
E/FlutterSecureStoragePl(26649): java.security.InvalidKeyException: Failed to unwrap key
E/FlutterSecureStoragePl(26649): at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineUnwrap(AndroidKeyStoreCipherSpiBase.java:682)
E/FlutterSecureStoragePl(26649): at javax.crypto.Cipher.unwrap(Cipher.java:2126)
E/FlutterSecureStoragePl(26649): at com.it_nomads.fluttersecurestorage.ciphers.RSACipher18Implementation.unwrap(RSACipher18Implementation.java:46)
E/FlutterSecureStoragePl(26649): at com.it_nomads.fluttersecurestorage.ciphers.StorageCipher18Implementation.<init>(StorageCipher18Implementation.java:48)
E/FlutterSecureStoragePl(26649): at com.it_nomads.fluttersecurestorage.FlutterSecureStoragePlugin.<init>(FlutterSecureStoragePlugin.java:46)
E/FlutterSecureStoragePl(26649): at com.it_nomads.fluttersecurestorage.FlutterSecureStoragePlugin.registerWith(FlutterSecureStoragePlugin.java:33)
E/FlutterSecureStoragePl(26649): at io.flutter.plugins.GeneratedPluginRegistrant.registerWith(GeneratedPluginRegistrant.java:18)
E/FlutterSecureStoragePl(26649): at net.it.cirrus.pocketbank.MainActivity.onCreate(MainActivity.java:15)
E/FlutterSecureStoragePl(26649): at android.app.Activity.performCreate(Activity.java:7087)
E/FlutterSecureStoragePl(26649): at android.app.Activity.performCreate(Activity.java:7078)
E/FlutterSecureStoragePl(26649): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1215)
E/FlutterSecureStoragePl(26649): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2763)
E/FlutterSecureStoragePl(26649): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2888)
E/FlutterSecureStoragePl(26649): at android.app.ActivityThread.-wrap11(Unknown Source:0)
E/FlutterSecureStoragePl(26649): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1609)
E/FlutterSecureStoragePl(26649): at android.os.Handler.dispatchMessage(Handler.java:106)
E/FlutterSecureStoragePl(26649): at android.os.Looper.loop(Looper.java:171)
E/FlutterSecureStoragePl(26649): at android.app.ActivityThread.main(ActivityThread.java:6606)
E/FlutterSecureStoragePl(26649): at java.lang.reflect.Method.invoke(Native Method)
E/FlutterSecureStoragePl(26649): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:518)
E/FlutterSecureStoragePl(26649): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
E/FlutterSecureStoragePl(26649): Caused by: javax.crypto.IllegalBlockSizeException
E/FlutterSecureStoragePl(26649): at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineDoFinal(AndroidKeyStoreCipherSpiBase.java:519)
E/FlutterSecureStoragePl(26649): at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineUnwrap(AndroidKeyStoreCipherSpiBase.java:680)
E/FlutterSecureStoragePl(26649): ... 20 more
E/FlutterSecureStoragePl(26649): Caused by: android.security.KeyStoreException: Unknown error
E/FlutterSecureStoragePl(26649): at android.security.KeyStore.getKeyStoreException(KeyStore.java:697)
E/FlutterSecureStoragePl(26649): at android.security.keystore.KeyStoreCryptoOperationChunkedStreamer.doFinal(KeyStoreCryptoOperationChunkedStreamer.java:224)
E/FlutterSecureStoragePl(26649): at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineDoFinal(AndroidKeyStoreCipherSpiBase.java:506)
E/FlutterSecureStoragePl(26649): ... 21 more
D/OpenGLRenderer(26649): HWUI GL Pipeline
I/flutter (26649): MissingPluginException(No implementation found for method read on channel plugins.it_nomads.com/flutter_secure_storage)
I/flutter (26649): #0 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:278:7)
I/flutter (26649): <asynchronous suspension>
I/flutter (26649): #1 FlutterSecureStorage.read (package:flutter_secure_storage/flutter_secure_storage.dart:16:24)
I/flutter (26649): <asynchronous suspension>
I/flutter (26649): #2 SecureStorage.read (file:///Users/ecampohermoso/data/pocketX/front-mobile/lib/helpers/secure_storage.dart:16:36)
I/flutter (26649): <asynchronous suspension>
I/flutter (26649): #3 _AffiliationPage.initState.<anonymous closure> (file:///Users/ecampohermoso/data/pocketX/front-mobile/lib/pages/affiliation.dart:60:23)
I/flutter (26649): #4 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:990:15)
I/flutter (26649): #5 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:938:9)
I/flutter (26649): #6 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/scheduler/b
I/OpenGLRenderer(26649): Initialized EGL, version 1.4
D/OpenGLRenderer(26649): Swap behavior 2
My Flutter Doctor
[✓] Flutter (Channel beta, v0.7.3, on Mac OS X 10.12.6 16G1510, locale es-BO)
[✓] Android toolchain - develop for Android devices (Android SDK 27.0.3)
[✓] iOS toolchain - develop for iOS devices (Xcode 9.2)
[✓] Android Studio (version 3.0)
[!] IntelliJ IDEA Ultimate Edition (version 2018.2.1)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
[✓] VS Code (version 1.27.0)
[✓] Connected devices (1 available)
from flutter_secure_storage.
I found two similar issues:
https://stackoverflow.com/questions/36652675/java-security-unrecoverablekeyexception-failed-to-obtain-information-about-priv
https://stackoverflow.com/questions/36488219/android-security-keystoreexception-invalid-key-blob
I applied this hack and pushed branch with it. Please try version from branch hack_for_get_entry
Add to pubspec.yaml
flutter_secure_storage:
git:
url: [email protected]:mogol/flutter_secure_storage.git
ref: hack_for_get_entry
from flutter_secure_storage.
Fighting with the same problem right now. Your branch unfortunately did not change things for me. Without having investigated the call chains in detail, I did notice that the repeat loop was around a different place than the one the exception appears to be thrown from (unwrap). Is that intentional, like an early test?
The most notable oddity, however, is that all builds work flawlessly up to a versionCode of 17. Any build with a higher number fails, any build with a lower number works. Does that help in any way?
from flutter_secure_storage.
I've made a separate implementation on flutter_keychain which seems to be working fine for me now.
from flutter_secure_storage.
The most notable oddity, however, is that all builds work flawlessly up to a versionCode of 17. Any build with a higher number fails, any build with a lower number works. Does that help in any way?
@tom95 , I am testing on 8.1.0 and still not able to reproduce. So couldn't get the reason why the secret key is encrypted by another key pair.
For now I can add fallback logic: if unwrapping failed, delete all data and start from scratch.
Would it work?
from flutter_secure_storage.
@mogol Ah I did actually mean the app's versionCode, not the OS's. I have no clue why, but any versionCode in the app/build.gradle of 17 or lower threw no error. Starting from 18 any versionCode I tried (18, 19, 20, 100, 1000) exhibited the error. I have not tried reproducing that in an isolated environment, but this is the exact behavior as observed in our app.
I believe just deleting the data on error should be an opt-in fallback, since that may discard valuable info. I can see how that info is not accessible anyways currently, but if a proper fix comes up at some point I would prefer for the data to still be there.
from flutter_secure_storage.
Let's discuss the fix in #23
thanks to @hnvn
from flutter_secure_storage.
Please try v3.1.2.
from flutter_secure_storage.
Thanks, @Sdlion . This solution worked for me. I was encountering this error in both development and release modes. In the case of the release mode, I cleared my cache and restarted my phone to resolve it, but I was able to solve it through the method you suggested. Thanks
from flutter_secure_storage.
from flutter_secure_storage.
Related Issues (20)
- > Failed to transform android.jar to match attributes {artifactType=android-platform-attr, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}. HOT 2
- InfoSec Documentation for Windows is missing
- Question about files on Windows platform
- Getting values in separate isolate fails - Code: -25308, Message: User interaction is not allowed HOT 7
- Reading a specific key or using read all returns a null from the store HOT 1
- Running on web fails when _selectOptions are called
- Recording with encrypted data
- Linux read always empty
- Cannot compile my project with AGP >=8.0.0 due to R8 error HOT 2
- I am trying to save data but for some reason it is not saved on Flutter web (Chrome)
- app run crash on macos m1 pro HOT 2
- After reopen application, getting null values in IOS. But working in Android. HOT 10
- flutter_secure_storage for web get error: type LegacyJavaScriptObject is not a subtype of FutureOr<CryptoKey> HOT 1
- Error while reading data on windows HOT 1
- SHA-1 is a weak hash known to have hash collisions.
- App uses the encryption mode CBC with PKCS5/PKCS7 padding
- After reopen application, getting null values in IOS. But working in Android HOT 1
- Null check operator used on a null value
- iOS: Breaking Change from 9.1.x forward, causing loss of data HOT 3
- Datas are not removed when app is uninstalled - I0S HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flutter_secure_storage.