cioccarellia / ksprefs

Kotlin SharedPreferences wrapper & cryptographic android library.
https://cioccarellia.github.io/ksprefs/
Apache License 2.0
228 stars 22 forks source link

javax.crypto.IllegalBlockSizeException when pulling value consecutively #40

Closed patzootz closed 1 year ago

patzootz commented 3 years ago

I'm using ksprefs library and from time to time i get javax.crypto.IllegalBlockSizeException I've found that if 2 threads or 2 calls are made at the same time the app crashes with the above exception. I can easily recreate the crash using these lines on samsung galaxy tab:

    for (i in 1..10){
        lifecycleScope.launch(Dispatchers.Default){
            val isEnabled = ZoeyApp.prefs.pull(booleanKey, true)
            Log.d("Testing", isEnabled.toString())
        }
    }

I have the prefs set us as such:

val prefs by lazy { KsPrefs(context) {
   encryptionType = EncryptionType.KeyStore("prefs")
}}

Thank you very much for the great lib!

cioccarellia commented 2 years ago

Sorry for the delay, will look into this as soon as I get the chance. Maybe there is some synchronization issue. I don't see a clear way out since the library is basically a wrapper for shared preferences.

cioccarellia commented 1 year ago

Better late than never haha, just added multithreading support, pushing now