从Truststore中删除证书程序

时间:2016-05-30 15:49:14

标签: java certificate x509certificate keystore truststore

我尝试从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(别名),但证书仍在信任库中。没有错误,应用程序运行没有任何问题。

我错了什么?

提前致谢。 : - )

1 个答案:

答案 0 :(得分:1)

尝试存储结果

 OutputStream writeStream = new FileOutputStream(filePathToStore);
 keystore.store(writeStream, password);
 writeStream.close();