import java.security.*;
import java.security.spec.*;
import java.io.*;
import java.util.*;
import java.security.cert.*;
import java.math.BigInteger;
import java.util.Date;
import javax.crypto.Cipher;
import org.bouncycastle.jce.provider.*;
public class CertificateCheck {
private Principal subDn;
public boolean CertificateCheck()
{
try {
FileInputStream fin=null;
DataInputStream din=null;
java.security.cert.CertificateFactory CertFactory=java.security.cert.CertificateFactory.getInstance("X.509"); //初始化CertificateFactory
//证书信息
fin=new FileInputStream("My.cert");//证书文件名
din=new DataInputStream(fin);
cert = (X509Certificate)CertFactory.generateCertificate(din);
this.subDn=cert.getSubjectDN() ; //得到证书主题。其中就可以放一些信息,如用户信息等
int ver=cert.getVersion() ; //证书版本
String type=cert.getType() ; //Example x.509
BigInteger serialNum=cert.getSerialNumber();//RETURN the serial number(序列号);An integer assigned by CA
PublicKey pubKey=cert.getPublicKey() ; //获得公钥
Date notBefore=cert.getNotBefore() ; //the start date of the validity period
Date notAfter=cert.getNotAfter() ; //the end date of the validity period.
byte[] sigNature=cert.getSignature() ; //返回签名数据;(CA签名)
String sigName=cert.getSigAlgName() ; //获得签名算法
fin.close();
din.close() ;
}catch(Exception e){e.printStackTrace();}
}
public Principal getSubDn()
{
return this.subDn ;
}
}