我试图只用Java获取和读取证书。我应该查看哪些代码或示例来获取网站的证书。
例如网站:
我是否使用网址类?
URL url = new URL("https://google.com");
答案 0 :(得分:6)
好的,我刚刚知道如何获取我想要的信息。
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());
}
}
}