Package java.security.cert

Examples of java.security.cert.CertificateFactory


     */
    public static Certificate[] getCertificateChain(byte[] bArray)
            throws Exception {
        try {

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

            InputStream certStream = getStream(bArray);

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

            if (c.size() == 1) {
                certStream = getStream(bArray);
                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


                                if( subFilter.getName().equals( "adbe.x509.rsa_sha1" ) )
                                {
                                    COSString certString = (COSString)cert.getDictionaryObject(
                                        COSName.getPDFName( "Cert" ) );
                                    byte[] certData = certString.getBytes();
                                    CertificateFactory factory = CertificateFactory.getInstance( "X.509" );
                                    ByteArrayInputStream certStream = new ByteArrayInputStream( certData );
                                    Collection certs = factory.generateCertificates( certStream );
                                    System.out.println( "certs=" + certs );
                                }
                                else if( subFilter.getName().equals( "adbe.pkcs7.sha1" ) )
                                {
                                    COSString certString = (COSString)cert.getDictionaryObject(
                                        COSName.getPDFName( "Contents" ) );
                                    byte[] certData = certString.getBytes();
                                    CertificateFactory factory = CertificateFactory.getInstance( "X.509" );
                                    ByteArrayInputStream certStream = new ByteArrayInputStream( certData );
                                    Collection certs = factory.generateCertificates( certStream );
                                    System.out.println( "certs=" + certs );
                                }
                                else
                                {
                                    System.err.println( "Unknown certificate type:" + subFilter );
View Full Code Here

     * @throws Exception If there is an error during the test.
     */
    public void testMultipleRecipients() throws Exception
    {           
       
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
       
        PDDocument doc = PDDocument.load(input);
       
        PublicKeyProtectionPolicy ppp = new PublicKeyProtectionPolicy();
       
        PublicKeyRecipient recip1 = new PublicKeyRecipient();
        PublicKeyRecipient recip2 = new PublicKeyRecipient();
       
        recip1.setPermission(accessPermission);
        recip2.setPermission(accessPermission2);
       
        InputStream inStream = new FileInputStream(publicCert1);       
        Assert.assertNotNull(cf);
        X509Certificate certificate1 = (X509Certificate)cf.generateCertificate(inStream);
        inStream.close();       
       
        InputStream inStream2 = new FileInputStream(publicCert2);       
        Assert.assertNotNull(cf);
        X509Certificate certificate2 = (X509Certificate)cf.generateCertificate(inStream2);
        inStream.close();       
       
        recip1.setX509(certificate1);
        recip2.setX509(certificate2);
       
View Full Code Here

   
   
    private void protect(PDDocument doc, String certPath) throws Exception
    {
        InputStream inStream = new FileInputStream(certPath);
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        Assert.assertNotNull(cf);
        X509Certificate certificate = (X509Certificate)cf.generateCertificate(inStream);
        Assert.assertNotNull(certificate);
        inStream.close();       
       
        PublicKeyProtectionPolicy ppp = new PublicKeyProtectionPolicy();               
        PublicKeyRecipient recip = new PublicKeyRecipient();
View Full Code Here

                        PublicKeyProtectionPolicy ppp = new PublicKeyProtectionPolicy();
                        PublicKeyRecipient recip = new PublicKeyRecipient();
                        recip.setPermission(ap);
                       
                       
                        CertificateFactory cf = CertificateFactory.getInstance("X.509");                           
                        InputStream inStream = new FileInputStream(certFile);
                        X509Certificate certificate = (X509Certificate)cf.generateCertificate(inStream);
                        inStream.close();
                       
                        recip.setX509(certificate);
                       
                        ppp.addRecipient(recip);
View Full Code Here

    if (_clientCert.size() == 0)
      return;

    try {
      CertificateFactory cf = CertificateFactory.getInstance("X.509");
      InputStream is = _clientCert.createInputStream();
      X509Certificate cert = (X509Certificate) cf.generateCertificate(is);
      is.close();

      request.setAttribute("javax.servlet.request.X509Certificate",
                           new X509Certificate[]{cert});
      request.setAttribute(com.caucho.security.AbstractLogin.LOGIN_USER_NAME,
View Full Code Here

    int len = getClientCertificate(_fd, buffer, 0, buffer.length);
    X509Certificate cert = null;

    if (len > 0 && len < buffer.length) {
      try {
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        InputStream is = new ByteArrayInputStream(buffer, 0, len);
        cert = (X509Certificate) cf.generateCertificate(is);
        is.close();
      } catch (IOException e) {
        return null;
      }
    }
View Full Code Here

    private static X509Certificate getRawCertificate(XMLSignatureInput resource)
        throws CanonicalizationException, IOException, CertificateException {
        byte inputBytes[] = resource.getBytes();    
        // 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));
        return cert;
    }
View Full Code Here

            for (File currentCert : certs) {
                FileInputStream inStream = new FileInputStream(currentCert);
                BufferedInputStream bis = new BufferedInputStream(inStream);

                CertificateFactory certFactory = CertificateFactory.getInstance("X509");
                Certificate cert = certFactory.generateCertificate(bis);

                trustStore.setCertificateEntry(currentCert.getName(), cert);

                bis.close();
                inStream.close();
View Full Code Here

            }

            FileInputStream certInputStream = new FileInputStream(certFile);
            BufferedInputStream certBufferedInputStream = new BufferedInputStream(certInputStream);

            CertificateFactory certFactory = CertificateFactory.getInstance("X509");
            Certificate cert = certFactory.generateCertificate(certBufferedInputStream);

            certBufferedInputStream.close();
            certInputStream.close();

View Full Code Here

TOP

Related Classes of java.security.cert.CertificateFactory

Copyright © 2018 www.massapicom. 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.