-
-
Notifications
You must be signed in to change notification settings - Fork 404
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
Unhandled Exception: PlatformException(Exception encountered, read, javax.crypto.BadPaddingException: error:1e000065:Cipher functions:OPENSSL_internal:BAD_DECRYPT #161
Comments
I'm also experiencing the same problem
PlatformException(Exception encountered, read, javax.crypto.BadPaddingException: error:1e000065:Cipher functions:OPENSSL_internal:BAD_DECRYPT |
I used this workaround by adding to AndroidManifest.xml |
@bettdouglas this doesnt seem to work anymore. |
I encounter this too when running the app for the 2nd time. |
I got the same problem. |
I have the same problem. But the bug only triggers some of the time. I always reproduce it
|
I downgraded to 3.3.3 and the issue disappeared. |
I'm having the same problem on 3.3.3 Repost: Version 3.3.4 with <application ... android:allowBackup="false" android:fullBackupContent="false"> Seem to solve the problem for me. |
I added |
I got the same problem with 3.3.3 and 3.3.4, but when downgraded to 3.3.2 it works fine for me |
Used 3.3.2 then 3.3.1+1 it's still a problem.. |
@sydneyagcaoili Double check if the version also changed in the pubspec.lock file |
@Andrew-Bekhiet I have same issue also tried with deleting pubspec.lock file. Any further solution. Device Samsung S10+(Android 10) |
@sandeeppatel1986 Just for double-checking, go to your |
If anyone has consistent failures, could you please provide a steps to reproduce from scratch? If you change manifest, I believe you have to delete and then reinstall the app with new manifest, simple relaunch shouldn't help. |
@mogol I haven't tried to reproduce this problem due to my schedule currently. I will try to do it today. I haven't changed the manifest in the file since a long time. I had flutter_secure_storage v3.3.3 and it worked. It was when I upgraded to v3.3.4 that I started seeing this error message. I fixed the error by reverting to v3.3.3. My pubspec.yaml has: |
I'm having this issue on 3.3.4- 3.3.1 versions with Flutter 1.22. I didn't find any solution. I had to remove this lib from the project |
Roughly 1% of my users are having this problem -- I'm currently using Flutter 1.20.4 and Dart 2.9.2. I haven't found a direct correlation amongst them. I added code at the same time I went from 3.3.3 to 3.3.4 to allow them to report this particular error so it may have been happening before. @mogol I'll let you know if I'm able to replicate in a demo project. For those moving to another library, what did you choose? |
This is randomly happening for me too. The payload that causes it for me is a largeish json string that I unfortunately cannot share here. I appreciate this great library, and thank you for all the work you've done for it. But unfortunately, this kind of bug is a no-go for this kind of a library that we must be able to trust. I realize that you are probably developing this library on your spare time, but I hope you find time to fix this soon. |
Here's a reproduction. Create a new app using Replace the content of import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Secure storage bug',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Secure storage bug'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final secureStorage1 = FlutterSecureStorage();
Future<void> write() async {
for (int i = 0; i < 100; ++i) {
secureStorage1.write(key: 'TEST1', value: 'a');
secureStorage1.write(key: 'TEST2', value: 'a');
}
}
Future<void> read() async {
for (int i = 0; i < 100; ++i) {
secureStorage1.read(key: 'TEST1');
secureStorage1.read(key: 'TEST2');
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
RaisedButton(
child: Text('write'),
onPressed: write,
),
RaisedButton(
child: Text('read'),
onPressed: read,
),
],
),
),
);
}
}
Click So this seems to happen when I run multiple read/write operations in parallel. |
A temporary workaround would be to serialize all calls to this library and to only use one class AsyncMutex {
Completer<void> _completer;
Future<void> lock() async {
while (_completer != null) {
await _completer.future;
}
_completer = Completer<void>();
}
void unlock() {
assert(_completer != null);
final completer = _completer;
_completer = null;
completer.complete();
}
}
class SecureStorage {
static const _secureStorage = FlutterSecureStorage();
static final _mutex = AsyncMutex();
Future<String> read({String key}) async {
try {
await _mutex.lock();
return await _secureStorage.read(key: key);
} finally {
_mutex.unlock();
}
}
Future<void> write({String key, String value}) async {
try {
await _mutex.lock();
await _secureStorage.write(key: key, value: value);
} finally {
_mutex.unlock();
}
}
} |
Looking at the android code, it seems that it's all completely thread-unsafe. this method is run in a separate thread for each call, and there's no synchronization whatsoever for any method calls except for the Thread safety was destroyed in this commit |
I'm developing two very similar apps, both using secure storage. Somehow I encountered this problem in only one of those two apps. I tried all the fixes in this issue but none of those worked for me. I really need this package for my project, any alternative? |
@koskimas thanks for repro case 🎉 , I was looking for it quite a while. Let me try it 👍 |
@mogol No problem! Took me a good while too 😅 I think many of the other issues here in github are caused by the thread safety issues too. The cipher classes are not thread safe, but they are called from different threads for each flutter call. Every time two calls run in parallel, things can easily go wrong. The correct solution, I think, would be to have only one worker thread in android native code, in which all operations are run. That way the code doesn't lock the android main thread, and the code is thread safe. HandlerThread could be a good solution. |
@mogol I'd be happy to provide a PR for fixing the thread safety issues. Are you already working on the fix or should I start? |
Hey Sami,
I was planning to check on the weekends. So if you can do it early 👍 it’s fine.
Sent from ProtonMail Mobile
…On Thu, Oct 8, 2020 at 10:21, Sami Koskimäki ***@***.***> wrote:
***@***.***(https://github.com/mogol) I'd be happy to provide a PR for fixing the thread safety issues. Are you already working on the fix or should I start?
—
You are receiving this because you were mentioned.
Reply to this email directly, [view it on GitHub](#161 (comment)), or [unsubscribe](https://github.com/notifications/unsubscribe-auth/AA2JY7QG3K23KDWIID6SLFLSJVR7NANCNFSM4RWNS3SA).
|
If you make the mutex global you can also use multiple instances, in case it is non-trivial to adapt your app to have a single instance for now and you need a quick fix. Of course not having global variables is cleaner code. |
This error happens only in production in the play store. Huawei android 10. Tried this:
But I still get the error. Using |
I am using version 3.3.5 in the production and since few days ago I started getting sentry reports with following error log:
I tried to reproduce the bug, and I manage to do it. Devices that I have tested it Samsung s9 and Samsung s10e => error, Huawei P20 Pro is working and not crashing.
I don't know if this log is helpful, but this is actually a really huge bug. |
Hey guys, the problem might be setting a key as empty String, at least for me that was it. I know the thread is closed, by anyways, it could help someone else. |
I think @dluanoliveira1 got it, for example I am using this plugin and at the start of the app I am reading a value that might be stored. But when I first start the app (after 1st install) there are no keys registered yet, so it gives back that BAD DECRYPT error when it tries to read a key that does not exist. |
I am still facing the same issue in release build, I am using flutter_secure_storage: ^4.2.0 |
I'm still facing the issue in 4.2.1 and none of the above solutions work, its surprising, a package of 99% popularity is still having the issue reopened again and again :-( |
I have same issue with flutter_secure_storage: ^4.2.0 in Android 11 on samsung s20. |
Same issue with flutter_secure_storage: ^4.2.0 |
Just ran into this issue with a Google Pixel 6 Pro tried with: |
I am also facing this error. |
Same error here |
Same issue with flutter_secure_storage: 4.2.0 |
Still same issue with flutter_secure_storage: 4.2.1 |
Still same issue with flutter_secure_storage: 5.0.2 (but happens only on some real devices, never on emulator ) |
Have you checked if you are reading a value that does not exist? |
Having the same Problem with 5.0.2 and i am, too, trying to read a key that doesn't exist yet. Is there a way to check first if the key exists or not? Tried it with try catch first, which worked, then tried by adding android:allowBackup="false" in AndroidManifest.xml, which fixed the issue, too. |
This line caused the error to me |
I had the same problem with version ^4.2.1 and ^5.0.2 on Samsung J737A which didn't use to happen for a while until I upgraded all my packages. I realized the problem was caused by reading keys that did not yet exist. I solved it by use a simply try catch, and returned null on error, (I think null is the default return value when a key is not found anyways). static Future getToken() async { |
If you use version
This causes the package to use Android's built-in EncryptedSharedPreferences. The crash only seems to occur when not using this setting, because then the package uses a different way of encrypting and decrypting the prefs. You can see that by reading the source code here: https://github.com/mogol/flutter_secure_storage/blob/26efe91a75228ad8c8626d6eea18f7f3cb21bdd9/flutter_secure_storage/android/src/main/java/com/it_nomads/fluttersecurestorage/FlutterSecureStoragePlugin.java#L101 Also see #328 (comment) |
Thanks it works for me |
I am still experiencing this issue. Any ideas on how to resolve it? |
How to fix this problem?
The text was updated successfully, but these errors were encountered: