JSP获取数字证书相关信息

阅读更多

SSL加密通道获取数字证书相关信息

X509Certificate[] certs = (X509Certificate[]) request.getAttribute("javax.servlet.request.X509Certificate");
try {
	certs[0].checkValidity(); //检查证书的有效期
			
	for (X509Certificate cert : certs) {
		System.out.println("版本:\t" + cert.getVersion());
		System.out.println("序列号: \t" + cert.getSerialNumber());
		System.out.println("颁布者: \t" + cert.getIssuerDN().getName());
		System.out.println("使用者(主题项): \t" + cert.getSubjectDN().getName());
		System.out.println("签名算法: \t" + cert.getSigAlgName());
		System.out.println("证书类型: \t" + cert.getType());
		System.out.println("有效期从: \t" + cert.getNotBefore());
		System.out.println("至: \t" + cert.getNotAfter());
	}
} catch (CertificateExpiredException e) {
	e.printStackTrace();
} catch (CertificateNotYetValidException e) {
	e.printStackTrace();
}

 

你可能感兴趣的:(Java,数字证书,jsp)