单身贵族英文
java检查本地cer证书(转)
import java.io.FileInputStream;
import CertificateExpiredException;
import CertificateFactory;
import CertificateNotYetValidException;
本振频率import X509Certificate;
import java.util.Calendar;
import java.util.Date;
public class CheckCertValid {
public static void main(String args[]) throws Exception {
// 获取X509Certificate的对象
/
/ 从命令⾏中读⼊需要验证的证书⽂件
CertificateFactory of = Instance("x.509");
FileInputStream in = new FileInputStream("D:/");
Certificate ceof = of.generateCertificate(in);
System.out.PublicKey().getEncoded() + "\t"
beefcake+ Encoded());
in.clo();
dxsX509Certificate t = (X509Certificate) ceof;
// 获取⽇期
// 验证证书在某个⽇期是否有效,从命令⾏读⼊年⽉⽇,由此⽣成Date()对象。有Date类的很多设置年⽉⽇的⽅法已经不提倡使⽤,因此改⽤Calendar类,Calendar Calendar cld = Instance();
int year = Integer.parInt("2012");
int month = Integer.parInt("9");
int day = Integer.parInt("24");
cld.t(year, month, day);
Date d = Time();
System.out.println(d);
try {
// 检验证书
t.checkValidity(d);
System.out.print("OK");
}
/
babysteps/ 处理CertificateExpiredException异常
// 若证书在指定⽇期已经过期,则产⽣CertificateExpiredException异常,在cath语句中作相关处理
catch (CertificateExpiredException e) {
System.out.println("expired");
System.out.Message());
}
// 处理CertificateNorYetValidException异常betsy
// 若证书在指定⽇期尚未⽣效,则产⽣CertificateNorYetValidException异常,在cath语句中作相关处理
显见
priortocatch (CertificateNotYetValidException e) {
System.out.println("Too early");
System.out.Message());
方便的英文}放鸽子英文
}
}