Example usage for org.bouncycastle.asn1.pkcs ContentInfo getEncoded

List of usage examples for org.bouncycastle.asn1.pkcs ContentInfo getEncoded

Introduction

In this page you can find the example usage for org.bouncycastle.asn1.pkcs ContentInfo getEncoded.

Prototype

public byte[] getEncoded() throws IOException 

Source Link

Document

Return the default BER or DER encoding for this object.

Usage

From source file:ca.trustpoint.m2m.M2mCertPath.java

License:Apache License

/**
 * Encode the CertPath using PKCS#7 format.
 *
 * @return a byte array containing the binary encoding of the PKCS#7 object
 * @exception CertificateEncodingException if an exception occurs
 *///from   www  .  j  a v  a2s .  c om
private byte[] encodePkcs7() throws CertificateEncodingException {
    ASN1EncodableVector encodedList = new ASN1EncodableVector();

    for (M2mCertificate certificate : certificates) {
        if (isDuplicateCertificate(certificate)) {
            throw new CertificateEncodingException("Duplicate certificate detected in path.");
        }

        try {
            encodedList.add(ASN1Primitive.fromByteArray(certificate.getEncoded()));
        } catch (IOException ex) {
            throw new CertificateEncodingException("Error encoding certificate data.", ex);
        }
    }

    SignedData sd = new SignedData(new ASN1Integer(BigInteger.ONE), // version
            new DERSet(), // digestAlgorithmIds
            new ContentInfo(PKCSObjectIdentifiers.data, null), // contentInfo
            new DERSet(encodedList), // certificates (optional)
            null, // CRLs (optional)
            new DERSet() // signerInfos
    );

    // make it a content info sequence
    ContentInfo ci = new ContentInfo(PKCSObjectIdentifiers.data, sd);

    try {
        return ci.getEncoded();
    } catch (IOException ex) {
        throw new CertificateEncodingException("Error encoding certificate path.", ex);
    }
}