我尝试从JAVA中的Truststore程序中删除证书。
public static void deleteCertificate(final File trustStore, final String password, final String alias) {
try (final FileInputStream fis = new FileInputStream(trustStore)) {
final KeyStore keystore = KeyStore.getInstance("UBER");
keystore.load(fis, password.toCharArray());
if (keystore.containsAlias(alias)) {
keystore.deleteEntry(alias);
}
else {
throw new IllegalStateException("Alias " + alias + " not found in trust store");
}
}
catch (final Exception e) {
throw new IllegalStateException("Error occures while deleting certificate.", e);
Programm传递行keystore.deleteEntry(别名),但证书仍在信任库中。没有错误,应用程序运行没有任何问题。
我错了什么?
提前致谢。 : - )
答案 0 :(得分:1)
尝试存储结果
OutputStream writeStream = new FileOutputStream(filePathToStore);
keystore.store(writeStream, password);
writeStream.close();