Java XPath Get getCertificateFromKeyInfo(Node keyInfoNode)

Here you can find the source of getCertificateFromKeyInfo(Node keyInfoNode)

Description

get Certificate From Key Info

License

Apache License

Declaration

public static X509Certificate getCertificateFromKeyInfo(Node keyInfoNode)
            throws ParserConfigurationException, SAXException, IOException 

Method Source Code


//package com.java2s;
/*//ww  w .  ja  v a2 s  .  com
 * Copyright 2010 University of Chicago
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * NOTE: This is a _PROTOTYPE_ implementation and is not intended for
 *       production use.
 * @src https://svn.cagrid.org/trunk/cagrid/restsecurity/cagrid-restsecurity-common/src/main/java/org/cagrid/security/rest/util/SecurityUtil.java
 */

import java.io.ByteArrayInputStream;

import java.io.IOException;

import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;

import javax.xml.parsers.ParserConfigurationException;

import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;

import org.apache.commons.codec.binary.Base64;

import org.w3c.dom.Node;

import org.xml.sax.SAXException;

public class Main {
    static XPathExpression x509Path = null;
    static CertificateFactory certFactory = null;

    public static X509Certificate getCertificateFromKeyInfo(Node keyInfoNode)
            throws ParserConfigurationException, SAXException, IOException {
        X509Certificate cert = null;

        try {
            String s = x509Path.evaluate(keyInfoNode);
            if (s == null || s.length() == 0)
                return null;
            byte[] decoded = Base64.decodeBase64(s);
            cert = (X509Certificate) certFactory.generateCertificate(new ByteArrayInputStream(decoded));
        } catch (XPathExpressionException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (CertificateException e) {
            e.printStackTrace();
        }
        return cert;
    }
}

Related

  1. get(String path, Node e)
  2. getAttribute(String fileName, String xPathExpression, String attributeName)
  3. getBaseLocation(byte[] metadata)
  4. getBool(Node node, boolean def, XPathExpression expr)
  5. getCache()
  6. getCruxPagesXPath()
  7. getDefaultXPath()
  8. getDefaultXPathFactory()
  9. getDigestValue(Node reference)