Fatal Exception: java.security.ProviderException: Keystore key generation failed
at android.security.keystore2.AndroidKeyStoreKeyGeneratorSpi.engineGenerateKey(AndroidKeyStoreKeyGeneratorSpi.java:413)
at javax.crypto.KeyGenerator.generateKey(KeyGenerator.java:612)
at androidx.security.crypto.MasterKeys.generateKey(MasterKeys.java:130)
at androidx.security.crypto.MasterKeys.getOrCreate(MasterKeys.java:88)
at com.redmadrobot.pinkman.Pinkman$encryptedStorage$2.invoke(Pinkman.kt:52)
at com.redmadrobot.pinkman.Pinkman$encryptedStorage$2.invoke(Pinkman.kt:22)
at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
at com.redmadrobot.pinkman.Pinkman.getEncryptedStorage(:2)
at com.redmadrobot.pinkman.Pinkman.createPin(Pinkman.kt:67)
at com.redmadrobot.pinkman.Pinkman.createPin$default(Pinkman.kt:58)
at *****.invokeSuspend(*****)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTaskKt.resume(DispatchedTask.kt:234)
at kotlinx.coroutines.DispatchedTaskKt.dispatch(DispatchedTask.kt:166)
at kotlinx.coroutines.CancellableContinuationImpl.dispatchResume(CancellableContinuationImpl.kt:397)
at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl(CancellableContinuationImpl.kt:431)
at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl$default(CancellableContinuationImpl.kt:420)
at kotlinx.coroutines.CancellableContinuationImpl.resumeUndispatched(CancellableContinuationImpl.kt:518)
at kotlinx.coroutines.android.HandlerContext$scheduleResumeAfterDelay$$inlined$Runnable$1.run(Runnable.kt:19)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7842)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
Caused by android.security.KeyStoreException: System error
at android.security.KeyStore2.getKeyStoreException(KeyStore2.java:334)
at android.security.KeyStoreSecurityLevel.handleExceptions(KeyStoreSecurityLevel.java:57)
at android.security.KeyStoreSecurityLevel.generateKey(KeyStoreSecurityLevel.java:145)
at android.security.keystore2.AndroidKeyStoreKeyGeneratorSpi.engineGenerateKey(AndroidKeyStoreKeyGeneratorSpi.java:400)
at javax.crypto.KeyGenerator.generateKey(KeyGenerator.java:612)
at androidx.security.crypto.MasterKeys.generateKey(MasterKeys.java:130)
at androidx.security.crypto.MasterKeys.getOrCreate(MasterKeys.java:88)
at com.redmadrobot.pinkman.Pinkman$encryptedStorage$2.invoke(Pinkman.kt:52)
at com.redmadrobot.pinkman.Pinkman$encryptedStorage$2.invoke(Pinkman.kt:22)
at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
at com.redmadrobot.pinkman.Pinkman.getEncryptedStorage(:2)
at com.redmadrobot.pinkman.Pinkman.createPin(Pinkman.kt:67)
at com.redmadrobot.pinkman.Pinkman.createPin$default(Pinkman.kt:58)
at *****.invokeSuspend(*****)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTaskKt.resume(DispatchedTask.kt:234)
at kotlinx.coroutines.DispatchedTaskKt.dispatch(DispatchedTask.kt:166)
at kotlinx.coroutines.CancellableContinuationImpl.dispatchResume(CancellableContinuationImpl.kt:397)
at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl(CancellableContinuationImpl.kt:431)
at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl$default(CancellableContinuationImpl.kt:420)
at kotlinx.coroutines.CancellableContinuationImpl.resumeUndispatched(CancellableContinuationImpl.kt:518)
at kotlinx.coroutines.android.HandlerContext$scheduleResumeAfterDelay$$inlined$Runnable$1.run(Runnable.kt:19)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7842)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
Reproducing stable on android 12 (sdk 32), tested on real device and emulator. Right now workarounded it like this:
diff --git a/pinkman/src/main/java/com/redmadrobot/pinkman/Pinkman.kt b/pinkman/src/main/java/com/redmadrobot/pinkman/Pinkman.kt
index 4c12aaa..ebc5d17 100644
--- a/pinkman/src/main/java/com/redmadrobot/pinkman/Pinkman.kt
+++ b/pinkman/src/main/java/com/redmadrobot/pinkman/Pinkman.kt
@@ -34,7 +34,7 @@ class Pinkman(
.setEncryptionPaddings(ENCRYPTION_PADDING_NONE)
.setKeySize(KEY_SIZE)
.apply {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
+ if (Build.VERSION.SDK_INT in Build.VERSION_CODES.P..Build.VERSION_CODES.S) {
setUnlockedDeviceRequired(true)
val hasStrongBox = applicationContext