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(String encoding) throws CertificateEncodingException;

Source Link

Document

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

Usage

From source file:net.sf.keystore_explorer.crypto.x509.X509CertUtil.java

/**
 * PKCS #7 encode a number of certificates.
 *
 * @return The encoding/*  w  w w  . j  a  v a  2 s  .c  o m*/
 * @param certs
 *            The certificates
 * @throws CryptoException
 *             If there was a problem encoding the certificates
 */
public static byte[] getCertsEncodedPkcs7(X509Certificate[] certs) throws CryptoException {
    try {
        ArrayList<Certificate> encodedCerts = new ArrayList<Certificate>();

        Collections.addAll(encodedCerts, certs);

        CertificateFactory cf = CertificateFactory.getInstance(X509_CERT_TYPE, BOUNCY_CASTLE.jce());

        CertPath cp = cf.generateCertPath(encodedCerts);

        return cp.getEncoded(PKCS7_ENCODING);
    } catch (CertificateException e) {
        throw new CryptoException(res.getString("NoPkcs7Encode.exception.message"), e);
    } catch (NoSuchProviderException e) {
        throw new CryptoException(res.getString("NoPkcs7Encode.exception.message"), e);
    }
}

From source file:net.sf.keystore_explorer.crypto.x509.X509CertUtil.java

/**
 * PKI Path encode a number of certificates.
 *
 * @return The encoding//from w w w.  j a va  2 s .  c  o m
 * @param certs
 *            The certificates
 * @throws CryptoException
 *             If there was a problem encoding the certificates
 */
public static byte[] getCertsEncodedPkiPath(X509Certificate[] certs) throws CryptoException {
    try {
        ArrayList<Certificate> encodedCerts = new ArrayList<Certificate>();

        Collections.addAll(encodedCerts, certs);

        CertificateFactory cf = CertificateFactory.getInstance(X509_CERT_TYPE, BOUNCY_CASTLE.jce());

        CertPath cp = cf.generateCertPath(encodedCerts);

        return cp.getEncoded(PKI_PATH_ENCODING);
    } catch (CertificateException e) {
        throw new CryptoException(res.getString("NoPkcs7Encode.exception.message"), e);
    } catch (NoSuchProviderException e) {
        throw new CryptoException(res.getString("NoPkcs7Encode.exception.message"), e);
    }
}

From source file:org.kse.crypto.x509.X509CertUtil.java

/**
 * PKCS #7 encode a number of certificates.
 *
 * @return The encoding/*from   w w  w. j av  a  2  s  .c o m*/
 * @param certs
 *            The certificates
 * @throws CryptoException
 *             If there was a problem encoding the certificates
 */
public static byte[] getCertsEncodedPkcs7(X509Certificate[] certs) throws CryptoException {
    try {
        ArrayList<Certificate> encodedCerts = new ArrayList<Certificate>();

        Collections.addAll(encodedCerts, certs);

        CertificateFactory cf = CertificateFactory.getInstance(X509_CERT_TYPE, BOUNCY_CASTLE.jce());

        CertPath cp = cf.generateCertPath(encodedCerts);

        return cp.getEncoded(PKCS7_ENCODING);
    } catch (CertificateException | NoSuchProviderException e) {
        throw new CryptoException(res.getString("NoPkcs7Encode.exception.message"), e);
    }
}

From source file:org.kse.crypto.x509.X509CertUtil.java

/**
 * PKI Path encode a number of certificates.
 *
 * @return The encoding//from ww  w . j ava 2  s  .c o  m
 * @param certs
 *            The certificates
 * @throws CryptoException
 *             If there was a problem encoding the certificates
 */
public static byte[] getCertsEncodedPkiPath(X509Certificate[] certs) throws CryptoException {
    try {
        ArrayList<Certificate> encodedCerts = new ArrayList<Certificate>();

        Collections.addAll(encodedCerts, certs);

        CertificateFactory cf = CertificateFactory.getInstance(X509_CERT_TYPE, BOUNCY_CASTLE.jce());

        CertPath cp = cf.generateCertPath(encodedCerts);

        return cp.getEncoded(PKI_PATH_ENCODING);
    } catch (CertificateException | NoSuchProviderException e) {
        throw new CryptoException(res.getString("NoPkcs7Encode.exception.message"), e);
    }
}