- Get Server Certificate


How to get the server certificate of a HTTPS Website?

✍: FYIcenter


If you created a URL object with "new", you can use the getServerCertificates() method on the HttpsURLConnection class to get the server certificate of a HTTPS Website:

// Copyright (c)

public class GetServerCertificate {
   public static void main(String[] args) throws Exception {
    URL url = new URL("");
    System.out.println("URL Class Name: "+url.getClass().getName());

    URLConnection con = url.openConnection();
    System.out.println("Connection Class Name: "+con.getClass().getName());
    HttpsURLConnection scon = (HttpsURLConnection) con;
    Certificate[] certs = scon.getServerCertificates();
    System.out.println("Server Certificate: "+certs[0].toString());

You can compile and run the above example in a command window:


\fyicenter>\local\jdk-1.8.0\bin\java GetServerCertificate

URL Class Name:
Connection Class Name:
Server Certificate: [
  Version: V3
  Subject:, OU=Content Management Services IT, O=Oracle Corporation, 
  L=Redwood Shores, ST=California, C=US
  Signature Algorithm: SHA256withRSA, OID = 1.2.840.113549.1.1.11

  Key:  Sun RSA public key, 2048 bits
  modulus: 266007053589262198503910002916415210613237870471654508456672717076127...
  public exponent: 65537
  Validity: [From: Thu Apr 13 20:00:00,
               To: Wed Mar 28 19:59:59 EDT 2018]
  Issuer: CN=GeoTrust SSL CA - G3, O=GeoTrust Inc., C=US
  SerialNumber: [    5d547be2 37a12187 1c8849d9 09f1e3ee]

  ... - SSL Socket Client Example - HTTPS URL Information

Examples for jsse.jar - Java Secure Socket Extension

⇑⇑ FAQ for jsse.jar - Java Secure Socket Extension

2018-03-31, 3536🔥, 0💬