簡體   English   中英

如何獲取Java中的證書信息

[英]How to get the Certificate Information in Java

我試圖僅在Java中獲取和讀取證書。 我應該查看哪些代碼或示例來獲得網站的證書。

例如,網站:

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

我是否使用URL類?

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

好的,我剛剛發現如何獲得所需的信息。

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());
            }
        }
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM