Example usage for java.security.cert CertificateFactory getInstance

List of usage examples for java.security.cert CertificateFactory getInstance

Introduction

In this page you can find the example usage for java.security.cert CertificateFactory getInstance.

Prototype

public static final CertificateFactory getInstance(String type) throws CertificateException 

Source Link

Document

Returns a certificate factory object that implements the specified certificate type.

Usage

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    FileInputStream in = new FileInputStream(args[0]);
    X509CRL crl = (X509CRL) cf.generateCRL(in);
    System.out.println("type = " + crl.getType());
    System.out.println("version = " + crl.getVersion());
    System.out.println("issuer = " + crl.getIssuerDN().getName());
    System.out.println("signing algorithm = " + crl.getSigAlgName());
    System.out.println("this update = " + crl.getThisUpdate());
    System.out.println("next update = " + crl.getNextUpdate());
    in.close();//from   w ww. j  a  v  a  2s  . com
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {

    CertificateFactory certFactory = CertificateFactory.getInstance("X.509");

    FileInputStream fis = new FileInputStream("a.dat");

    Certificate cert = certFactory.generateCertificate(fis);
    fis.close();/* ww  w .jav  a 2 s. com*/

    System.out.println(cert);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    FileInputStream is = new FileInputStream(new File("your"));

    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    java.security.cert.Certificate cert = cf.generateCertificate(is);
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    FileInputStream fr = new FileInputStream("sdo.cer");
    CertificateFactory cf = CertificateFactory.getInstance("X509");
    X509Certificate c = (X509Certificate) cf.generateCertificate(fr);
    System.out.println("\tCertificate for: " + c.getSubjectDN());
    System.out.println("\tCertificate issued by: " + c.getIssuerDN());
    System.out.println("\tThe certificate is valid from " + c.getNotBefore() + " to " + c.getNotAfter());
    System.out.println("\tCertificate SN# " + c.getSerialNumber());
    System.out.println("\tGenerated with " + c.getSigAlgName());
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    List mylist = new ArrayList();
    for (int i = 0; i < args.length; i++) {
        FileInputStream in = new FileInputStream(args[i]);
        Certificate c = cf.generateCertificate(in);
        mylist.add(c);/*ww  w .  j  a v  a2s  . c o  m*/
    }
    CertPath cp = cf.generateCertPath(mylist);
    System.out.println(cp);
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    FileInputStream in = new FileInputStream(args[0]);
    java.security.cert.Certificate c = cf.generateCertificate(in);
    in.close();/*www .  j  ava  2s  .c  om*/

    X509Certificate t = (X509Certificate) c;
    System.out.println(t.getVersion());
    System.out.println(t.getSerialNumber().toString(16));
    System.out.println(t.getSubjectDN());
    System.out.println(t.getIssuerDN());
    System.out.println(t.getNotBefore());
    System.out.println(t.getNotAfter());
    System.out.println(t.getSigAlgName());
    byte[] sig = t.getSignature();
    System.out.println(new BigInteger(sig).toString(16));
    PublicKey pk = t.getPublicKey();
    byte[] pkenc = pk.getEncoded();
    for (int i = 0; i < pkenc.length; i++) {
        System.out.print(pkenc[i] + ",");
    }
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    FileInputStream in = new FileInputStream(args[0]);
    X509CRL crl = (X509CRL) cf.generateCRL(in);
    Set s = crl.getRevokedCertificates();
    if (s != null && s.isEmpty() == false) {
        Iterator t = s.iterator();
        while (t.hasNext()) {
            X509CRLEntry entry = (X509CRLEntry) t.next();
            System.out.println("serial number = " + entry.getSerialNumber().toString(16));
            System.out.println("revocation date = " + entry.getRevocationDate());
            System.out.println("extensions = " + entry.hasExtensions());
        }//from w ww.  j av a2  s .  c  om
    }
    in.close();
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {

    Certificate[] certpath = new Certificate[args.length - 1];
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    int i;/*from w  w w.  j a v a 2  s. c  om*/
    for (i = 0; i < args.length - 1; i++) {
        FileInputStream in = new FileInputStream(args[i]);
        certpath[i] = cf.generateCertificate(in);
    }
    FileInputStream in = new FileInputStream(args[i]);
    Certificate trust = cf.generateCertificate(in);

    boolean pass = false;
    String reason = "";
    for (i = 0; i < certpath.length; i++) {
        try {
            PublicKey pbk;
            if (i == certpath.length - 1) {
                pbk = trust.getPublicKey();
            } else {
                pbk = certpath[i + 1].getPublicKey();
            }
            certpath[i].verify(pbk);
            pass = true;
        } catch (Exception e) {
            pass = false;
            reason += i + "  " + e.toString();
            break;
        }
    }
    System.out.println(pass);
}

From source file:Main.java

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);
    }/* w ww  .j av  a2s .  co  m*/
    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;
        }
    }
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    List mylist = new ArrayList();
    for (int i = 0; i < args.length; i++) {
        FileInputStream in = new FileInputStream(args[i]);
        Certificate c = cf.generateCertificate(in);
        mylist.add(c);/*  w ww  . ja  v a2s. co  m*/
    }
    CertPath cp = cf.generateCertPath(mylist);
    List cplist = cp.getCertificates();
    Object[] o = cplist.toArray();
    for (int i = 0; i < o.length; i++) {
        X509Certificate c = (X509Certificate) o[i];
        System.out.println(c.getSubjectDN());
        byte[] pbk = c.getPublicKey().getEncoded();
        for (int j = 0; j < pbk.length; j++) {
            System.out.print(pbk[j] + ",");
        }
        System.out.println("\nIssued by " + c.getIssuerDN());
    }
}