Java tutorial
//package com.java2s; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import java.util.Date; public class Main { private static boolean verifyCertificateValidity(X509Certificate certificate) throws CertificateException { if (certificate != null) { if (certificate.getNotAfter().compareTo(new Date(System.currentTimeMillis())) >= 0) { return true; } throw new CertificateException("Certificate has expired and is not valid for signing document."); } return false; } }