Java校验.CER、.pem证书格式以及获取证书有效期
程序员文章站
2022-05-19 11:58:01
...
public static void main(String[] args) throws CertificateException, FileNotFoundException {
CertificateFactory cf = CertificateFactory.getInstance("X.509");
FileInputStream in = new FileInputStream("/Users/name/Downloads/cert.pem");
X509Certificate cert = (X509Certificate) cf.generateCertificate(in);
cert.checkValidity(); //校验格式,错误抛出异常,可捕捉
Date effDate = cert.getNotBefore();
Date expDate = cert.getNotAfter();
long diff = expDate.getTime() - effDate.getTime();
System.out.println(diff / (1000 * 60 * 60 * 24));
System.out.println(effDate);
System.out.println(expDate);
}
上一篇: python与mysql数据库交互
下一篇: R语言相关性