当前位置:   article > 正文

java 获取https ssl证书有效期等信息_java x509certificate getselfcertificate 过期时间

java x509certificate getselfcertificate 过期时间
  1. package com.hknaruto.cmdApp;
  2. import javax.net.ssl.HttpsURLConnection;
  3. import java.net.URL;
  4. import java.security.cert.Certificate;
  5. import java.security.cert.X509Certificate;
  6. public class Main {
  7. public static void main(String[] args) throws Exception {
  8. URL url = new URL("https://www.baidu.com");
  9. HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
  10. connection.connect();
  11. for (Certificate certificate : connection.getServerCertificates()) {
  12. //第一个就是服务器本身证书,后续的是证书链上的其他证书
  13. X509Certificate x509Certificate = (X509Certificate) certificate;
  14. System.out.println(x509Certificate.getSubjectDN());
  15. System.out.println(x509Certificate.getNotBefore());//有效期开始时间
  16. System.out.println(x509Certificate.getNotAfter());//有效期结束时间
  17. }
  18. connection.disconnect();
  19. }
  20. }

 

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号