Abe*_*res 5 encryption keystore kotlin android-keystore android-instant-apps
val masterKey =\n MasterKey\n .Builder(applicationContext)\n .setKeyScheme(MasterKey.KeyScheme.AES256_GCM)\n .build()\nRun Code Online (Sandbox Code Playgroud)\n在即时应用程序中运行此代码会使我的应用程序崩溃,并显示以下堆栈跟踪:
\n2020-12-21 13:07:29.654 28949-28949/com.example.instantappandroidkeystore E/AndroidRuntime: FATAL EXCEPTION: main\n Process: com.example.instantappandroidkeystore, PID: 28949\n java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.instantappandroidkeystore/com.example.instantappandroidkeystore.MainActivity}: java.lang.NullPointerException: Attempt to invoke interface method \'int android.security.keystore.IKeystoreService.exist(java.lang.String, int)\' on a null object reference\n at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3448)\n at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3595)\n at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)\n at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)\n at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)\n at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2147)\n at android.os.Handler.dispatchMessage(Handler.java:107)\n at android.os.Looper.loop(Looper.java:237)\n at android.app.ActivityThread.main(ActivityThread.java:7814)\n at java.lang.reflect.Method.invoke(Native Method)\n at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)\n at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1068)\n Caused by: java.lang.NullPointerException: Attempt to invoke interface method \'int android.security.keystore.IKeystoreService.exist(java.lang.String, int)\' on a null object reference\n at android.security.KeyStore.contains(KeyStore.java:408)\n at android.security.keystore.AndroidKeyStoreSpi.engineContainsAlias(AndroidKeyStoreSpi.java:1038)\n at java.security.KeyStore.containsAlias(KeyStore.java:1293)\n at androidx.security.crypto.MasterKeys.keyExists(MasterKeys.java:154)\n at androidx.security.crypto.MasterKeys.getOrCreate(MasterKeys.java:96)\n at androidx.security.crypto.MasterKey$Builder.buildOnM(MasterKey.java:357)\n at androidx.security.crypto.MasterKey$Builder.build(MasterKey.java:314)\n at com.example.instantappandroidkeystore.MainActivity.onCreate(MainActivity.kt:32)\n at android.app.Activity.performCreate(Activity.java:7955)\n at android.app.Activity.performCreate(Activity.java:7944)\n at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)\n at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3423)\n at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3595)\xc2\xa0\n at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)\xc2\xa0\n at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)\xc2\xa0\n at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)\xc2\xa0\n at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2147)\xc2\xa0\n at android.os.Handler.dispatchMessage(Handler.java:107)\xc2\xa0\n at android.os.Looper.loop(Looper.java:237)\xc2\xa0\n at android.app.ActivityThread.main(ActivityThread.java:7814)\xc2\xa0\n at java.lang.reflect.Method.invoke(Native Method)\xc2\xa0\n at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)\xc2\xa0\n at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1068)\xc2\xa0\n\nRun Code Online (Sandbox Code Playgroud)\n我没有运气在 StackOverflow 中找到这个问题,但我在 Google Issue Tracker 中找到了它,但没有任何回应。因此,我向 Google 提交了一个包含更多信息的问题。https://issuetracker.google.com/issues/176085956
\n有谁遇到过这个问题并且能够解决它。
\n我的工作环境是:
\n虽然这在developer.android 论坛上没有正式记录,但看起来 AndroidKeyStore 的访问权限仅限于即时应用程序。我发现了这个链接https://www.reddit.com/r/androiddev/comments/7a4tdw/why_no_hardware_backed_keystore_in_instant_apps/
这很奇怪,密钥库受到限制,并且没有 Android 文档对此进行解释。我不确定访问 KeyStore 的替代方案,因为我们的常规应用程序(非即时)非常依赖密钥库,而且我想不出更好的选择。期待建议!
| 归档时间: |
|
| 查看次数: |
1111 次 |
| 最近记录: |