android 6上的java密钥库崩溃

dwthyt8l  于 2021-06-30  发布在  Java
关注(0)|答案(0)|浏览(255)

我正在测试示例android密钥库应用程序,来自:https://github.com/googlesamples/android-basicandroidkeystore
但我在三星a3(2016)上遇到了崩溃,android 6.0.1(该设备有pin设置)。和这里描述的一样:https://github.com/googlesamples/android-basicandroidkeystore/issues/2 (不过,我在android p仿真器或任何其他设备上都没有看到这种崩溃)
所以,若要查看崩溃,我只需运行应用程序并单击菜单中的“创建”。
这里是stacktrace:

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.android.basicandroidkeystore, PID: 2694
java.security.ProviderException: Failed to load generated key pair from keystore
    at android.security.keystore.AndroidKeyStoreKeyPairGeneratorSpi.generateKeyPair(AndroidKeyStoreKeyPairGeneratorSpi.java:491)
    at java.security.KeyPairGenerator$KeyPairGeneratorImpl.generateKeyPair(KeyPairGenerator.java:276)
    at com.example.android.basicandroidkeystore.BasicAndroidKeyStoreFragment.createKeys(BasicAndroidKeyStoreFragment.java:211)
    at com.example.android.basicandroidkeystore.BasicAndroidKeyStoreFragment.onOptionsItemSelected(BasicAndroidKeyStoreFragment.java:89)
    at android.support.v4.app.Fragment.performOptionsItemSelected(Fragment.java:2394)
    at android.support.v4.app.FragmentManagerImpl.dispatchOptionsItemSelected(FragmentManager.java:3326)
    at android.support.v4.app.FragmentController.dispatchOptionsItemSelected(FragmentController.java:344)
    at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:386)
    at com.android.internal.policy.PhoneWindow.onMenuItemSelected(PhoneWindow.java:1249)
    at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:801)
    at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:158)
    at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:954)
    at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:944)
    at android.widget.ActionMenuView.invokeItem(ActionMenuView.java:726)
    at com.android.internal.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:239)
    at android.view.View.performClick(View.java:5714)
    at android.widget.TextView.performClick(TextView.java:10926)
    at android.view.View$PerformClick.run(View.java:22589)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:7325)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
 Caused by: java.security.UnrecoverableKeyException: Failed to obtain X.509 form of public key
    at android.security.keystore.AndroidKeyStoreProvider.loadAndroidKeyStorePublicKeyFromKeystore(AndroidKeyStoreProvider.java:223)
    at android.security.keystore.AndroidKeyStoreProvider.loadAndroidKeyStoreKeyPairFromKeystore(AndroidKeyStoreProvider.java:252)
    at android.security.keystore.AndroidKeyStoreKeyPairGeneratorSpi.generateKeyPair(AndroidKeyStoreKeyPairGeneratorSpi.java:488)
    at java.security.KeyPairGenerator$KeyPairGeneratorImpl.generateKeyPair(KeyPairGenerator.java:276) 
    at com.example.android.basicandroidkeystore.BasicAndroidKeyStoreFragment.createKeys(BasicAndroidKeyStoreFragment.java:211) 
    at com.example.android.basicandroidkeystore.BasicAndroidKeyStoreFragment.onOptionsItemSelected(BasicAndroidKeyStoreFragment.java:89) 
    at android.support.v4.app.Fragment.performOptionsItemSelected(Fragment.java:2394) 
    at android.support.v4.app.FragmentManagerImpl.dispatchOptionsItemSelected(FragmentManager.java:3326) 
    at android.support.v4.app.FragmentController.dispatchOptionsItemSelected(FragmentController.java:344) 
    at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:386) 
    at com.android.internal.policy.PhoneWindow.onMenuItemSelected(PhoneWindow.java:1249) 
    at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:801) 
    at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:158) 
    at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:954) 
    at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:944) 
    at android.widget.ActionMenuView.invokeItem(ActionMenuView.java:726) 
    at com.android.internal.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:239) 
    at android.view.View.performClick(View.java:5714) 
    at android.widget.TextView.performClick(TextView.java:10926) 
    at android.view.View$PerformClick.run(View.java:22589) 
    at android.os.Handler.handleCallback(Handler.java:739) 
    at android.os.Handler.dispatchMessage(Handler.java:95) 
    at android.os.Looper.loop(Looper.java:148) 
    at android.app.ActivityThread.main(ActivityThread.java:7325) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
 Caused by: android.security.KeyStoreException: OK
    at android.security.KeyStore.getKeyStoreException(KeyStore.java:918)
    at android.security.keystore.AndroidKeyStoreProvider.loadAndroidKeyStorePublicKeyFromKeystore(AndroidKeyStoreProvider.java:223) 
    at android.security.keystore.AndroidKeyStoreProvider.loadAndroidKeyStoreKeyPairFromKeystore(AndroidKeyStoreProvider.java:252) 
    at android.security.keystore.AndroidKeyStoreKeyPairGeneratorSpi.generateKeyPair(AndroidKeyStoreKeyPairGeneratorSpi.java:488) 
    at java.security.KeyPairGenerator$KeyPairGeneratorImpl.generateKeyPair(KeyPairGenerator.java:276) 
    at com.example.android.basicandroidkeystore.BasicAndroidKeyStoreFragment.createKeys(BasicAndroidKeyStoreFragment.java:211) 
    at com.example.android.basicandroidkeystore.BasicAndroidKeyStoreFragment.onOptionsItemSelected(BasicAndroidKeyStoreFragment.java:89) 
    at android.support.v4.app.Fragment.performOptionsItemSelected(Fragment.java:2394) 
    at android.support.v4.app.FragmentManagerImpl.dispatchOptionsItemSelected(FragmentManager.java:3326) 
    at android.support.v4.app.FragmentController.dispatchOptionsItemSelected(FragmentController.java:344) 
    at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:386) 
    at com.android.internal.policy.PhoneWindow.onMenuItemSelected(PhoneWindow.java:1249) 
    at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:801) 
    at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:158) 
    at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:954) 
    at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:944) 
    at android.widget.ActionMenuView.invokeItem(ActionMenuView.java:726) 
    at com.android.internal.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:239) 
    at android.view.View.performClick(View.java:5714) 
    at android.widget.TextView.performClick(TextView.java:10926) 
    at android.view.View$PerformClick.run(View.java:22589) 
    at android.os.Handler.handleCallback(Handler.java:739) 
    at android.os.Handler.dispatchMessage(Handler.java:95) 
    at android.os.Looper.loop(Looper.java:148) 
    at android.app.ActivityThread.main(ActivityThread.java:7325) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

特别是,此函数崩溃:https://github.com/googlesamples/android-basicandroidkeystore/blob/master/application/src/main/java/com/example/android/basicandroidkeystore/basicandroidkeystorefragment.java#l156
在这一行:https://github.com/googlesamples/android-basicandroidkeystore/blob/master/application/src/main/java/com/example/android/basicandroidkeystore/basicandroidkeystorefragment.java#l211
你知道怎么修吗?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题