将我们的应用程序上载到Google Play商店时,Google的发布前报告表明该应用程序崩溃了,并出现了空指针异常。问题仅与在华为设备中实施KeyStore有关。
Stacktrace:
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
}
我认为它必须与设备的密钥库实现有关。
任何帮助将不胜感激。
答案 0 :(得分:0)
禁用与AndroidKeysetManager.doNotUseKeystore()
的Keystore集成。