我正在使用 Android KeyStore 生成 key ,但在恢复出厂设置后该 key 被删除。 有办法避免这种情况吗? 这是我的代码 fragment :
if (keyStore.containsAlias(KEY_STORE_ALIAS)) {
Log.e(TAG, "key exist");
else {
KeyPairGenerator kpGenerator = KeyPairGenerator.getInstance("RSA", "AndroidKeyStore");
AlgorithmParameterSpec spec = null;
spec = new KeyGenParameterSpec.Builder(KEY_STORE_ALIAS,
KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT)
.setDigests(KeyProperties.DIGEST_SHA256, KeyProperties.DIGEST_SHA512)
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_RSA_PKCS1)
.setRandomizedEncryptionRequired(true)
.setUserAuthenticationRequired(false)
.build();
kpGenerator.initialize(spec);
KeyPair kp = kpGenerator.generateKeyPair();
Log.e(TAG, "generate new key");
}
最佳答案
Based on Android documentation
Use the Android Keystore provider to let an individual app store its own credentials that only the app itself can access.
当您从设备中卸载或删除应用程序时,与该应用程序关联的 KeyStore
提供程序实例将被删除。并且,显然在恢复出厂设置期间strong>您安装的所有应用程序都将被删除,因此这些应用程序的 KeyStore
实例也将被删除。
所以回答你的问题,
It is impossible to retain the Keys on Factory Reset
关于android - 让 Android KeyStore 能够在恢复出厂设置后幸存下来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68448386/