List of usage examples for java.security.cert CertificateFactory generateCertificate
public final Certificate generateCertificate(InputStream inStream) throws CertificateException
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 { Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()); KeyPair pair = generateRSAKeyPair(); ByteArrayOutputStream bOut = new ByteArrayOutputStream(); bOut.write(generateV1Certificate(pair).getEncoded()); bOut.close();/*from w ww.j a va2 s .c o m*/ InputStream in = new ByteArrayInputStream(bOut.toByteArray()); CertificateFactory fact = CertificateFactory.getInstance("X.509", "BC"); X509Certificate x509Cert = (X509Certificate) fact.generateCertificate(in); System.out.println("issuer: " + x509Cert.getIssuerX500Principal()); }
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();/* w ww . ja va 2 s. com*/ System.out.println(cert); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { X509CertSelector selec = new X509CertSelector(); CertificateFactory cf = CertificateFactory.getInstance("X.509"); FileInputStream in = new FileInputStream(args[0]); Certificate c = cf.generateCertificate(in); System.out.println(selec.match(c)); selec.setIssuer("CN=Peter,OU=Network Center," + "O=University,L=ZB,ST=Vancouver,C=CN"); System.out.println(selec.match(c)); Calendar cld = Calendar.getInstance(); int year = Integer.parseInt(args[1]); int month = Integer.parseInt(args[2]) - 1; int day = Integer.parseInt(args[3]); cld.set(year, month, day);//w w w . jav a2 s . c o m Date d = cld.getTime(); selec.setCertificateValid(d); System.out.println(selec.match(c)); BigInteger sn = new BigInteger("1039056963"); selec.setSerialNumber(sn); System.out.println(selec.match(c)); }
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();//w w w .j av a 2s. c o m 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 { String cacert = "mytest.cer"; String lfcert = "lf_signed.cer"; String lfstore = "lfkeystore"; char[] lfstorepass = "wshr.ut".toCharArray(); char[] lfkeypass = "wshr.ut".toCharArray(); CertificateFactory cf = CertificateFactory.getInstance("X.509"); FileInputStream in1 = new FileInputStream(cacert); java.security.cert.Certificate cac = cf.generateCertificate(in1); in1.close();// w ww. ja va 2 s. c om FileInputStream in2 = new FileInputStream(lfcert); java.security.cert.Certificate lfc = cf.generateCertificate(in2); in2.close(); java.security.cert.Certificate[] cchain = { lfc, cac }; FileInputStream in3 = new FileInputStream(lfstore); KeyStore ks = KeyStore.getInstance("JKS"); ks.load(in3, lfstorepass); PrivateKey prk = (PrivateKey) ks.getKey("lf", lfkeypass); ks.setKeyEntry("lf_signed", prk, lfstorepass, cchain); FileOutputStream out4 = new FileOutputStream("lfnewstore"); ks.store(out4, "newpass".toCharArray()); out4.close(); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { CertificateFactory cf = CertificateFactory.getInstance("X.509"); List mylist = new ArrayList(); FileInputStream in = new FileInputStream(args[0]); Certificate c = cf.generateCertificate(in); mylist.add(c);/*from w ww.ja v a2 s . c o m*/ CertPath cp = cf.generateCertPath(mylist); Certificate trust = cf.generateCertificate(in); TrustAnchor anchor = new TrustAnchor((X509Certificate) trust, null); PKIXParameters params = new PKIXParameters(Collections.singleton(anchor)); params.setRevocationEnabled(false); CertPathValidator cpv = CertPathValidator.getInstance("PKIX"); PKIXCertPathValidatorResult result = (PKIXCertPathValidatorResult) cpv.validate(cp, params); System.out.println(result); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { CertificateFactory cf = CertificateFactory.getInstance("X.509"); List mylist = new ArrayList(); FileInputStream in = new FileInputStream(args[0]); Certificate c = cf.generateCertificate(in); mylist.add(c);//from ww w. ja v a 2 s . c o m CertStoreParameters cparam = new CollectionCertStoreParameters(mylist); CertStore cs = CertStore.getInstance("Collection", cparam); X509CertSelector selec = new X509CertSelector(); selec.setIssuer("CN=YourName,OU=Network Center," + "O=University,L=ZB,ST=Toronto,C=CN"); Set clct = (Set) cs.getCertificates(selec); Object o[] = clct.toArray(); for (int i = 0; i < o.length; i++) { X509Certificate ct = (X509Certificate) o[i]; System.out.println("Certificate " + i + " "); System.out.println(ct.getSubjectDN()); } }
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); }/*from ww w. j ava2 s.c o 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; } } }