FileDocCategorySizeDatePackage
CMSEnvelopedData.javaAPI DocBouncy Castle Crypto API 1.41 (Java 1.5)6449Wed Oct 01 10:55:28 BST 2008org.bouncycastle.cms

CMSEnvelopedData

public class CMSEnvelopedData extends Object
containing class for an CMS Enveloped Data object

Fields Summary
RecipientInformationStore
recipientInfoStore
org.bouncycastle.asn1.cms.ContentInfo
contentInfo
private org.bouncycastle.asn1.x509.AlgorithmIdentifier
encAlg
private org.bouncycastle.asn1.ASN1Set
unprotectedAttributes
Constructors Summary
public CMSEnvelopedData(byte[] envelopedData)

        this(CMSUtils.readContentInfo(envelopedData));
    
public CMSEnvelopedData(InputStream envelopedData)

        this(CMSUtils.readContentInfo(envelopedData));
    
public CMSEnvelopedData(org.bouncycastle.asn1.cms.ContentInfo contentInfo)

        this.contentInfo = contentInfo;

        EnvelopedData  envData = EnvelopedData.getInstance(contentInfo.getContent());

        //
        // read the encrypted content info
        //
        EncryptedContentInfo encInfo = envData.getEncryptedContentInfo();

        this.encAlg = encInfo.getContentEncryptionAlgorithm();

        //
        // load the RecipientInfoStore
        //
        ASN1Set     s = envData.getRecipientInfos();
        List        infos = new ArrayList();
        byte[]      contentOctets = encInfo.getEncryptedContent().getOctets();

        for (int i = 0; i != s.size(); i++)
        {
            RecipientInfo   info = RecipientInfo.getInstance(s.getObjectAt(i));
            InputStream     contentStream = new ByteArrayInputStream(contentOctets);
            Object          type = info.getInfo();

            if (type instanceof KeyTransRecipientInfo)
            {
                infos.add(new KeyTransRecipientInformation(
                    (KeyTransRecipientInfo)type, encAlg, contentStream));
            }
            else if (type instanceof KEKRecipientInfo)
            {
                infos.add(new KEKRecipientInformation(
                    (KEKRecipientInfo)type, encAlg, contentStream));
            }
            else if (type instanceof KeyAgreeRecipientInfo)
            {
                infos.add(new KeyAgreeRecipientInformation(
                    (KeyAgreeRecipientInfo)type, encAlg, contentStream));
            }
            else if (type instanceof PasswordRecipientInfo)
            {
                infos.add(new PasswordRecipientInformation(
                    (PasswordRecipientInfo)type, encAlg, contentStream));
            }
        }

        this.recipientInfoStore = new RecipientInformationStore(infos);
        this.unprotectedAttributes = envData.getUnprotectedAttrs();
    
Methods Summary
private byte[]encodeObj(org.bouncycastle.asn1.DEREncodable obj)

        if (obj != null)
        {
            return obj.getDERObject().getEncoded();
        }

        return null;
    
public org.bouncycastle.asn1.cms.ContentInfogetContentInfo()
return the ContentInfo

        return contentInfo;
    
public byte[]getEncoded()
return the ASN.1 encoded representation of this object.

        return contentInfo.getEncoded();
    
public java.lang.StringgetEncryptionAlgOID()
return the object identifier for the content encryption algorithm.

        return encAlg.getObjectId().getId();
    
public byte[]getEncryptionAlgParams()
return the ASN.1 encoded encryption algorithm parameters, or null if there aren't any.

        try
        {
            return encodeObj(encAlg.getParameters());
        }
        catch (Exception e)
        {
            throw new RuntimeException("exception getting encryption parameters " + e);
        }
    
public java.security.AlgorithmParametersgetEncryptionAlgorithmParameters(java.lang.String provider)
Return an AlgorithmParameters object giving the encryption parameters used to encrypt the message content.

param
provider the provider to generate the parameters for.
return
the parameters object, null if there is not one.
throws
CMSException if the algorithm cannot be found, or the parameters can't be parsed.
throws
NoSuchProviderException if the provider cannot be found.

        return getEncryptionAlgorithmParameters(CMSUtils.getProvider(provider));
    
public java.security.AlgorithmParametersgetEncryptionAlgorithmParameters(java.security.Provider provider)
Return an AlgorithmParameters object giving the encryption parameters used to encrypt the message content.

param
provider the provider to generate the parameters for.
return
the parameters object, null if there is not one.
throws
CMSException if the algorithm cannot be found, or the parameters can't be parsed.

        return CMSEnvelopedHelper.INSTANCE.getEncryptionAlgorithmParameters(getEncryptionAlgOID(), getEncryptionAlgParams(), provider);
    
public RecipientInformationStoregetRecipientInfos()
return a store of the intended recipients for this message

        return recipientInfoStore;
    
public org.bouncycastle.asn1.cms.AttributeTablegetUnprotectedAttributes()
return a table of the unprotected attributes indexed by the OID of the attribute.

        if (unprotectedAttributes == null)
        {
            return null;
        }

        return new AttributeTable(unprotectedAttributes);