Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (102)
JavaBeans (21)
JDBC (121)
JDK (426)
JSP (20)
Logging (108)
Mail (58)
Messaging (8)
Network (84)
PDF (97)
Report (7)
Scripting (84)
Security (32)
Server (121)
Servlet (26)
SOAP (24)
Testing (54)
Web (15)
XML (322)
Collections:
Other Resources:
GetServerCertificate.java - Get Server Certificate
How to get the server certificate of a HTTPS Website?
✍: FYIcenter
If you created a URL object with "new java.net.URL(...)",
you can use the getServerCertificates() method on the HttpsURLConnection class
to get the server certificate of a HTTPS Website:
// Copyright (c) FYIcenter.com
import java.net.*;
import java.io.*;
import javax.net.ssl.*;
import java.security.cert.*;
public class GetServerCertificate {
public static void main(String[] args) throws Exception {
URL url = new URL("https://www.oracle.com/");
System.out.println();
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;
scon.connect();
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\javac GetServerCertificate.java
\fyicenter>\local\jdk-1.8.0\bin\java GetServerCertificate
URL Class Name: java.net.URL
Connection Class Name: sun.net.www.protocol.https.HttpsURLConnectionImpl
Server Certificate: [
[
Version: V3
Subject: CN=www.oracle.com, 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]
...
⇒ SslSocketClient.java - SSL Socket Client Example
⇐ HttpsUrlInfo.java - HTTPS URL Information
2018-03-31, ∼4642🔥, 0💬
Popular Posts:
What Is poi-ooxml-3.5.jar? poi-ooxml-3.5.jar is one of the JAR files for Apache POI 3.5, which provi...
JDK 17 jdk.internal.le.jmod is the JMOD file for JDK 17 Internal Line Editing module. JDK 17 Interna...
JDK 11 jdk.jdeps.jmod is the JMOD file for JDK 11 JDeps tool, which can be invoked by the "jdeps" co...
What Is junit-3.8.1.jar? junit-3.8.1.jar is the version 3.8.1 of JUnit JAR library file. JUnit is a ...
JDK 11 jdk.internal.vm.compiler .jmodis the JMOD file for JDK 11 Internal VM Compiler module. JDK 11...