将我们的应用程序上传到 Google Play 商店时,谷歌的预发布报告表明该应用程序正在崩溃并出现空指针异常。该问题仅与华为设备中的 KeyStore 实施有关。
堆栈跟踪:
Fatal Exception: java.lang.NullPointerException: Attempt to invoke interface method 'int android.security.IKeystoreService.del(java.lang.String, int)' on a null object reference
at android.security.KeyStore.delete(KeyStore.java:186)
at android.security.Credentials.deletePrivateKeyTypeForAlias(Credentials.java:292)
at android.security.Credentials.deleteAllTypesForAlias(Credentials.java:251)
at android.security.keystore.AndroidKeyStoreKeyPairGeneratorSpi.generateKeyPair(AndroidKeyStoreKeyPairGeneratorSpi.java:464)
at java.security.KeyPairGenerator$Delegate.generateKeyPair(KeyPairGenerator.java:699)
at com.example.utility.crypto.KeyStoreHelper.createKeys(Unknown Source)
at com.example.utility.crypto.KeyStoreHelper.createKeys(Unknown Source)
at com.example.activities.register.SplashActivity$1.run(Unknown Source)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:255)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:776)
我正在使用 Google 的Tink库来实现 Keystore。图书馆与错误无关。没有库仍然会发生错误。
下面是代码:
@Throws(Exception::class)
private fun getOrGenerateNewKeysetHandle(): KeysetHandle {
return AndroidKeysetManager.Builder()
.withSharedPref(this, "KEYSET", "PREF")
.withKeyTemplate(AeadKeyTemplates.AES256_GCM)
.withMasterKeyUri(REIWA_MASTER_KEY_URI)
.build()
.keysetHandle
}
我认为这与设备的密钥库实现有关。
任何帮助将不胜感激。