How to get the Certificate Information in Java

后端 未结 1 1958
走了就别回头了
走了就别回头了 2021-01-13 10:21

I am trying to get and read a certificate only in Java. What code or examples should I look at to get the certificates of a website.

For examples the websites:

相关标签:
1条回答
  • 2021-01-13 11:15

    Ok I just found out how I can get the information that I want.

    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());
                }
            }
        }
    
    0 讨论(0)
提交回复
热议问题