flutter_secure_storage icon indicating copy to clipboard operation
flutter_secure_storage copied to clipboard

PlatformException (PlatformException(Exception encountered, read, javax.crypto.BadPaddingException: error:1e000065:Cipher functions:OPENSSL_internal:BAD_DECRYPT

Open SteveJosephh21 opened this issue 10 months ago • 9 comments

Hi, I have used secure storage plugin flutter_secure_storage: 9.0.0. Below is the complete error.

Exception has occurred. PlatformException (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.OpenSSLEvpCipher.doFinalInternal(OpenSSLEvpCipher.java:152) at com.android.org.conscrypt.OpenSSLCipher.engineDoFinal(OpenSSLCipher.java:374) at javax.crypto.Cipher.doFinal(Cipher.java:2055) at com.it_nomads.fluttersecurestorage.ciphers.StorageCipher18Implementation.decrypt(StorageCipher18Implementation.java:93) at com.it_nomads.fluttersecurestorage.FlutterSecureStorage.decodeRawValue(FlutterSecureStorage.java:249) at com.it_nomads.fluttersecurestorage.FlutterSecureStorage.read(FlutterSecureStorage.java:69) at com.it_nomads.fluttersecurestorage.FlutterSecureStoragePlugin$MethodRunner.run(FlutterSecureStoragePlugin.java:156) at android.os.Handler.handleCallback(Handler.java:938) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:236) at android.os.HandlerThread.run(HandlerThread.java:67) , null))

The line is throwing this error is secureStorage.read(key: 'key').

I have tried the below code but still this issue is happening. any news?

final FlutterSecureStorage storage = const FlutterSecureStorage( aOptions: AndroidOptions( encryptedSharedPreferences: true, ), );

SteveJosephh21 avatar Jan 20 '25 04:01 SteveJosephh21

The error originates from the legacy part of encryptedSharedPreferences, that is being phased out in v10.0.0.

This is what the android docs have to say about it

// Note that {@link BadPaddingException} includes {@link AEADBadTagException}. // This may happen if the encrypted keyset is corrupted, or if it was encrypted // with a different master key. You need to decide how to handle this. You may recover from // this by creating a new encrypted keyset, but then you need to delete all data that had // been encrypted with the old key.

You can use resetOnError which removes all data if such an error occurs.

juliansteenbakker avatar Jan 26 '25 15:01 juliansteenbakker

The error originates from the legacy part of encryptedSharedPreferences, that is being phased out in v10.0.0.

This is what the android docs have to say about it

// Note that {@link BadPaddingException} includes {@link AEADBadTagException}. // This may happen if the encrypted keyset is corrupted, or if it was encrypted // with a different master key. You need to decide how to handle this. You may recover from // this by creating a new encrypted keyset, but then you need to delete all data that had // been encrypted with the old key.

You can use resetOnError which removes all data if such an error occurs.

any idea when the 10 will be released?

jttuboi avatar Feb 20 '25 17:02 jttuboi

Hello, only customers have reported this issue and I cannot reproduce it. In order to confirm the fix, how do I reproduce it?

my customers have same problem on v9.0.0 && v9.2.4 Does it resolve on ^10.0.0-beta.4? v10.0.0-bata.4 also need to set resetOnError?

hakama99 avatar Mar 28 '25 01:03 hakama99

I have the same issue on Samsung.

Den-creator avatar Mar 28 '25 12:03 Den-creator

Has anyone found a solution?

pooja96km avatar Apr 01 '25 06:04 pooja96km

Using version ^10.0.0-beta.4 resolved the error.

pooja96km avatar Apr 04 '25 11:04 pooja96km

@pooja96km are u reproduce or test this issue on 10.0.0-beta.4?

nitipat009 avatar Apr 05 '25 17:04 nitipat009

⚠️ This issue has been marked as stale because it has been open for 60 days with no activity.

If this issue is still relevant, please comment to keep it active. Otherwise, it will be closed in 60 days.

github-actions[bot] avatar Jun 05 '25 03:06 github-actions[bot]

Has anyone found a solution?

SteveJosephh21 avatar Jun 05 '25 05:06 SteveJosephh21

⚠️ This issue has been marked as stale because it has been open for 60 days with no activity.

If this issue is still relevant, please comment to keep it active. Otherwise, it will be closed in 60 days.

github-actions[bot] avatar Aug 05 '25 03:08 github-actions[bot]

I was able to reproduce this issue on a Samsung S23 Ultra when executing the read instruction of FlutterSecureStorage. Upgrading flutter_secure_storage from 9.2.4 to 10.0.0-beta.4 resolves the problem:

- flutter_secure_storage: ^9.2.4
+ flutter_secure_storage: 10.0.0-beta.4

moezbaccouche avatar Oct 11 '25 13:10 moezbaccouche