Examples of CertificateFactory


Examples of java.security.cert.CertificateFactory

    Enumeration enumx = ((ASN1Sequence)derObject).getObjects();
    InputStream certInStream;
    ByteArrayOutputStream outStream;
    DEROutputStream derOutStream;
    certificates = new ArrayList();
    CertificateFactory certFactory= CertificateFactory.getInstance( "X.509", "BC" );
    while ( enumx.hasMoreElements() ) {
        outStream = new ByteArrayOutputStream();
        derOutStream = new DEROutputStream(outStream);
   
              derOutStream.writeObject(enumx.nextElement());
              derOutStream.close();

        certInStream = new ByteArrayInputStream(outStream.toByteArray());
        certificates.add(0,certFactory.generateCertificate(certInStream));
    }
      }
      else
      {
    throw new CertificateException( "unsupported encoding" );
View Full Code Here

Examples of java.security.cert.CertificateFactory

            //TODO could support multiple trust cas
            TrustManager[] trustStoreManagers = new TrustManager[1];
            
            KeyStore trustedCertStore = KeyStore.getInstance(trustStoreType);
            trustedCertStore.load(null, "".toCharArray());
            CertificateFactory cf = CertificateFactory.getInstance(CERTIFICATE_FACTORY_TYPE);
            byte[] caCert = loadCACert(trustStoreLocation);
            try {
                if (caCert != null) {
                    ByteArrayInputStream cabin = new ByteArrayInputStream(caCert);
                    X509Certificate cert = (X509Certificate)cf.generateCertificate(cabin);
                    trustedCertStore.setCertificateEntry(cert.getIssuerDN().toString(), cert);
                    cabin.close();
                }
            } catch (Exception e) {
                LogUtils.log(LOG, Level.WARNING, "FAILED_TO_LOAD_TRUST_STORE",
View Full Code Here

Examples of java.security.cert.CertificateFactory

    */
   public X509Certificate getX509Certificate() throws XMLSecurityException {

      try {
         byte certbytes[] = this.getCertificateBytes();
         CertificateFactory certFact =
            CertificateFactory.getInstance(XMLX509Certificate.JCA_CERT_ID);
         X509Certificate cert =
            (X509Certificate) certFact
               .generateCertificate(new ByteArrayInputStream(certbytes));

         if (cert != null) {
            return cert;
         }
View Full Code Here

Examples of java.security.cert.CertificateFactory

         if (currentFileName.endsWith(".crt")) {
            al.add(names[i]);
         }
      }

      CertificateFactory cf = null;

      try {
         cf = CertificateFactory.getInstance("X.509");
      } catch (CertificateException ex) {
         throw new StorageResolverException("empty", ex);
      }

      if (cf == null) {
         throw new StorageResolverException("empty");
      }

      for (int i = 0; i < al.size(); i++) {
         String filename = certDir.getAbsolutePath() + File.separator
                           + (String) al.get(i);
         File file = new File(filename);
         boolean added = false;
         String dn = null;

         try {
            FileInputStream fis = new FileInputStream(file);
            X509Certificate cert =
               (X509Certificate) cf.generateCertificate(fis);

            fis.close();

            //add to ArrayList
            cert.checkValidity();
View Full Code Here

Examples of java.security.cert.CertificateFactory

            byte inputBytes[] = resource.getBytes();

            if ((type != null) && type.equals(RetrievalMethod.TYPE_RAWX509)) {

               // if the resource stores a raw certificate, we have to handle it
               CertificateFactory certFact =
                  CertificateFactory
                     .getInstance(XMLX509Certificate.JCA_CERT_ID);
               X509Certificate cert =
                  (X509Certificate) certFact
                     .generateCertificate(new ByteArrayInputStream(inputBytes));

               if (cert != null) {
                  return cert.getPublicKey();
               }
View Full Code Here

Examples of java.security.cert.CertificateFactory

            if ((rm.getType() != null)
                    && rm.getType().equals(RetrievalMethod.TYPE_RAWX509)) {

               // if the resource stores a raw certificate, we have to handle it
               CertificateFactory certFact =
                  CertificateFactory
                     .getInstance(XMLX509Certificate.JCA_CERT_ID);
               X509Certificate cert =
                  (X509Certificate) certFact
                     .generateCertificate(new ByteArrayInputStream(inputBytes));

               if (cert != null) {
                  return cert;
               }
View Full Code Here

Examples of java.security.cert.CertificateFactory

        if (trustcacerts == null) {
            if (log.isInfoEnabled())
                log.info("Cannot validate from cacerts as the keystore failed to load.");
        } else {
            try {
                CertificateFactory certFact = CertificateFactory.getInstance("X.509");
                CertPath path = certFact.generateCertPath(Arrays.asList(chain));
                PKIXParameters params = new PKIXParameters(trustcacerts);
                params.setRevocationEnabled(false);
                CertPathValidator certPathValidator = CertPathValidator.getInstance(CertPathValidator.getDefaultType());
                CertPathValidatorResult result = certPathValidator.validate(path, params);
                PKIXCertPathValidatorResult pkixResult = (PKIXCertPathValidatorResult) result;
View Full Code Here

Examples of java.security.cert.CertificateFactory

        if (trustcacerts == null) {
          throw new CertificateException("No trust store found!");
        } else {
            try {
                CertificateFactory certFact = CertificateFactory.getInstance("X.509");
                CertPath path = certFact.generateCertPath(Arrays.asList(chain));
                PKIXParameters params = new PKIXParameters(trustcacerts);
                params.setRevocationEnabled(false);
                CertPathValidator certPathValidator = CertPathValidator.getInstance(CertPathValidator.getDefaultType());
                CertPathValidatorResult result = certPathValidator.validate(path, params);
                PKIXCertPathValidatorResult pkixResult = (PKIXCertPathValidatorResult) result;
View Full Code Here

Examples of java.security.cert.CertificateFactory

     */
    public static Certificate importCertificate(File file) throws Exception {
        try {
            FileInputStream is = new FileInputStream(file);

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

            /*
            if (cert instanceof X509Certificate) {
                X509Certificate x509cert = (X509Certificate) cert;

View Full Code Here

Examples of java.security.cert.CertificateFactory

     */
    public static Certificate[] getCertificateChain(String fileName)
            throws Exception {
        try {

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

            InputStream certStream = getStream(fileName);

            Collection c = cf.generateCertificates(certStream);
            Certificate[] certs = new Certificate[c.toArray().length];

            if (c.size() == 1) {
                certStream = getStream(fileName);
                System.out.println("1 certificate");
                Certificate cert = cf.generateCertificate(certStream);
                certs[0] = cert;
            } else {
                System.out.println("Certificate chain length: " + c.size());
                certs = (Certificate[]) c.toArray();
            }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.