This is my code:
val oldAlias = "oldAlias"
val newAlias = "newAlias"
if (keyStore.containsAlias(oldAlias) && keyStore.containsAlias(newAlias)) {
try {
deleteKeyStore(oldAlias)
val newEntry: KeyStore.Entry = keyStore.getEntry(newAlias, null)
keyStore.setEntry(oldAlias, newEntry, protParam = null) // exception is thrown here
deleteKeyStore(newAlias)
} catch (e: Exception) {
Timber.e(e)
}
}
I've tried running the method with and without deleting the oldAlias before calling the setEntry() method, but it doesn't help.
In both cases, if I don't delete the old alias or don't delete it, the method throws this exception:
KeyStoreException: Can only replace keys with the same alias: oldName != newName in the same target domain: 0 != 0
How can I replace the value by key in KeyStore?