Example usage for java.security.cert CertPath getEncoded

List of usage examples for java.security.cert CertPath getEncoded

Introduction

In this page you can find the example usage for java.security.cert CertPath getEncoded.

Prototype

public abstract byte[] getEncoded() throws CertificateEncodingException;

Source Link

Document

Returns the encoded form of this certification path, using the default encoding.

Usage

From source file:com.alfaariss.oa.profile.aselect.ws.security.OACrypto.java

/**
 * Retrieve /*from  www . j a va2 s . c o  m*/
 * @see Crypto#getCertificateData(boolean, X509Certificate[])
 */
public byte[] getCertificateData(boolean reverse, X509Certificate[] certs) throws WSSecurityException {

    try {
        Vector<X509Certificate> list = new Vector<X509Certificate>();
        for (int i = 0; i < certs.length; i++) {
            if (reverse) {
                list.insertElementAt(certs[i], 0);
            } else {
                list.add(certs[i]);
            }
        }
        CertPath path = getCertificateFactory().generateCertPath(list);
        return path.getEncoded();
    } catch (CertificateEncodingException e) {
        _logger.warn("Could not encode certificate path", e);
        throw new WSSecurityException(WSSecurityException.SECURITY_TOKEN_UNAVAILABLE, "encodeError", null, e);
    } catch (CertificateException e) {
        _logger.warn("Could not generate certificate path", e);
        throw new WSSecurityException(WSSecurityException.SECURITY_TOKEN_UNAVAILABLE, "parseError", null, e);
    }
}

From source file:org.apache.ws.security.components.crypto.CryptoBase.java

/**
 * get a byte array given an array of X509 certificates.
 * <p/>/*ww  w  . j  a  va  2 s . c o m*/
 *
 * @param reverse If set the first certificate in the array data will
 *                the last in the byte array
 * @param certs   The certificates to convert
 * @return The byte array for the certificates ordered according
 *         to the reverse flag
 * @throws WSSecurityException
 */
public byte[] getCertificateData(boolean reverse, X509Certificate[] certs) throws WSSecurityException {
    Vector list = new Vector();
    for (int i = 0; i < certs.length; i++) {
        if (reverse) {
            list.insertElementAt(certs[i], 0);
        } else {
            list.add(certs[i]);
        }
    }
    try {
        CertPath path = getCertificateFactory().generateCertPath(list);
        return path.getEncoded();
    } catch (CertificateEncodingException e) {
        throw new WSSecurityException(WSSecurityException.SECURITY_TOKEN_UNAVAILABLE, "encodeError", null, e);
    } catch (CertificateException e) {
        throw new WSSecurityException(WSSecurityException.SECURITY_TOKEN_UNAVAILABLE, "parseError", null, e);
    }
}

From source file:org.wso2.carbon.security.util.ServerCrypto.java

@Override
/**/*from w  w w  .j  ava 2s. co  m*/
 * @see org.apache.ws.security.components.crypto.Crypto#getCertificateData(boolean,
 * java.security.cert.X509Certificate[])
 */
public byte[] getCertificateData(boolean reverse, X509Certificate[] certs) throws WSSecurityException {
    Vector list = new Vector();
    for (int i = 0; i < certs.length; i++) {
        if (reverse) {
            list.insertElementAt(certs[i], 0);
        } else {
            list.add(certs[i]);
        }
    }
    try {
        CertPath path = getCertificateFactory().generateCertPath(list);
        return path.getEncoded();
    } catch (CertificateEncodingException e) {
        throw new WSSecurityException(WSSecurityException.SECURITY_TOKEN_UNAVAILABLE, "encodeError");
    } catch (CertificateException e) {
        throw new WSSecurityException(WSSecurityException.SECURITY_TOKEN_UNAVAILABLE, "parseError");
    }
}

From source file:org.wso2.carbon.webapp.ext.cxf.crypto.CXFServerCrypto.java

/**
 * @see org.apache.ws.security.components.crypto.Crypto#getCertificateData(boolean,
 *      java.security.cert.X509Certificate[])
 *//*from w  ww .  j a v  a  2  s.co  m*/
public byte[] getCertificateData(boolean reverse, X509Certificate[] certs) throws WSSecurityException {
    Vector list = new Vector();
    for (int i = 0; i < certs.length; i++) {
        if (reverse) {
            list.insertElementAt(certs[i], 0);
        } else {
            list.add(certs[i]);
        }
    }
    try {
        CertPath path = getCertificateFactory().generateCertPath(list);
        return path.getEncoded();
    } catch (CertificateEncodingException e) {
        throw new WSSecurityException(WSSecurityException.SECURITY_TOKEN_UNAVAILABLE, "encodeError");
    } catch (CertificateException e) {
        throw new WSSecurityException(WSSecurityException.SECURITY_TOKEN_UNAVAILABLE, "parseError");
    }
}