CertificateFactory: getInstance(String type) throws CertificateException : CertificateFactory « java.security.cert « Java by API






CertificateFactory: getInstance(String type) throws CertificateException

  
import java.io.FileInputStream;
import java.security.Principal;
import java.security.cert.Certificate;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;

public class Main {
  public static void main(String args[]) throws Exception {
    Certificate[] certpath = new Certificate[args.length];
    CertificateFactory cf = CertificateFactory.getInstance("X.509");

    for (int i = 0; i < args.length; i++) {
      FileInputStream in = new FileInputStream(args[i]);
      certpath[i] = cf.generateCertificate(in);
    }
    for (int i = 0; i < certpath.length - 1; i++) {
      Principal issuer = ((X509Certificate) certpath[i]).getIssuerDN();
      Principal subject = ((X509Certificate) certpath[i + 1]).getSubjectDN();
      if (!issuer.equals(subject)) {
        System.out.println("in " + i + " issuer is " + issuer);
        System.out.println("But in " + (i + 1));
        System.out.println("subject is " + subject);
        break;
      }
    }
  }
}

   
    
  








Related examples in the same category

1.CertificateFactory: generateCertPath(List certificates) throws CertificateException
2.CertificateFactory: generateCertificate(InputStream inStream) throws CertificateException