【问题标题】:How to get the Certificate Information in Java如何在 Java 中获取证书信息
【发布时间】:2014-04-23 06:47:58
【问题描述】:

我正在尝试仅在 Java 中获取和读取证书。我应该查看哪些代码或示例来获得网站的证书。

例如网站:

  1. https://google.com
  2. https://www.ssllabs.com/

我是否使用 URL 类?

URL url = new URL("https://google.com");

【问题讨论】:

标签: java certificate ssl-certificate


【解决方案1】:

好的,我刚刚发现了如何获得我想要的信息。

public void certInformation(String aURL) throws Exception{
        URL destinationURL = new URL(aURL);
        HttpsURLConnection conn = (HttpsURLConnection) destinationURL.openConnection();
        conn.connect();
        Certificate[] certs = conn.getServerCertificates();
        for (Certificate cert : certs) {
            System.out.println("Certificate is: " + cert);
            if(cert instanceof X509Certificate) {
                    X509Certificate x = (X509Certificate ) cert;
                    System.out.println(x.getIssuerDN());
            }
        }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-07
    • 2016-04-05
    • 1970-01-01
    • 2015-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-06
    相关资源
    最近更新 更多