Top Description Fields Constructors Methods
org.bouncycastle.cms

public Class CMSAuthenticatedDataParser

extends CMSContentInfoParser
Class Inheritance
Imports
java.io.ByteArrayInputStream, .IOException, .InputStream, org.bouncycastle.asn1.ASN1OctetString, .ASN1OctetStringParser, .ASN1SequenceParser, .ASN1Set, .ASN1SetParser, .BERTags, org.bouncycastle.asn1.cms.AttributeTable, .AuthenticatedDataParser, .CMSAttributes, .ContentInfoParser, .OriginatorInfo, org.bouncycastle.asn1.x509.AlgorithmIdentifier, org.bouncycastle.operator.DigestCalculatorProvider, .OperatorCreationException, org.bouncycastle.util.Arrays

Parsing class for an CMS Authenticated Data object from an input stream.

Note

that because we are in a streaming mode only one recipient can be tried and it is important that the methods on the parser are called in the appropriate order.

Example of use - assuming the first recipient matches the private key we have.

     CMSAuthenticatedDataParser     ad = new CMSAuthenticatedDataParser(inputStream);

     RecipientInformationStore  recipients = ad.getRecipientInfos();

     Collection  c = recipients.getRecipients();
     Iterator    it = c.iterator();

     if (it.hasNext())
     {
         RecipientInformation   recipient = (RecipientInformation)it.next();

         CMSTypedStream recData = recipient.getContentStream(new JceKeyTransAuthenticatedRecipient(privateKey).setProvider("BC"));

         processDataStream(recData.getContentStream());

         if (!Arrays.equals(ad.getMac(), recipient.getMac())
         {
             System.err.println("Data corrupted!!!!");
         }
     }
 
Note: this class does not introduce buffering - if you are processing large files you should create the parser with:
         CMSAuthenticatedDataParser     ep = new CMSAuthenticatedDataParser(new BufferedInputStream(inputStream, bufSize));
 
where bufSize is a suitably large buffer size.

Field Summary

Modifier and TypeField and Description
private boolean
private AttributeTable
private ASN1Set
pack-priv AuthenticatedDataParser
private byte[]
private AlgorithmIdentifier
private OriginatorInformation
pack-priv RecipientInformationStore
private CMSSecureReadable
private boolean
private AttributeTable
Inherited from org.bouncycastle.cms.CMSContentInfoParser:
_contentInfo_data

Constructor Summary

AccessConstructor and Description
public
CMSAuthenticatedDataParser(byte[] envelopedData)

public
CMSAuthenticatedDataParser(byte[] envelopedData, DigestCalculatorProvider digestCalculatorProvider)

public
public
CMSAuthenticatedDataParser(InputStream envelopedData, DigestCalculatorProvider digestCalculatorProvider)

Method Summary

Modifier and TypeMethod and Description
public AttributeTable
getAuthAttrs()

return a table of the unauthenticated attributes indexed by the OID of the attribute.

private ASN1Set
public byte[]

Returns:

the contents of the messageDigest attribute, if available. Null if not present.
getContentDigest
()

This will only be valid after the content has been read.

public byte[]
public String
getMacAlgOID()

return the object identifier for the mac algorithm.

public AlgorithmIdentifier

Returns:

AlgorithmIdentifier representing the MAC algorithm.
getMacAlgorithm
()

Return the MAC algorithm details for the MAC associated with the data in this object.

public byte[]
getMacAlgParams()

return the ASN.1 encoded encryption algorithm parameters, or null if there aren't any.

public OriginatorInformation

Returns:

OriginatorInformation, null if not present.
getOriginatorInfo
()

Return the originator information associated with this message if present.

public RecipientInformationStore
getRecipientInfos()

return a store of the intended recipients for this message

public AttributeTable
getUnauthAttrs()

return a table of the unauthenticated attributes indexed by the OID of the attribute.

Inherited from org.bouncycastle.cms.CMSContentInfoParser:
close

Field Detail

authAttrNotReadback to summary
private boolean authAttrNotRead
authAttrsback to summary
private AttributeTable authAttrs
authAttrSetback to summary
private ASN1Set authAttrSet
authDataback to summary
pack-priv AuthenticatedDataParser authData
macback to summary
private byte[] mac
macAlgback to summary
private AlgorithmIdentifier macAlg
originatorInfoback to summary
private OriginatorInformation originatorInfo
recipientInfoStoreback to summary
pack-priv RecipientInformationStore recipientInfoStore
secureReadableback to summary
private CMSSecureReadable secureReadable
unauthAttrNotReadback to summary
private boolean unauthAttrNotRead
unauthAttrsback to summary
private AttributeTable unauthAttrs

Constructor Detail

CMSAuthenticatedDataParserback to summary
public CMSAuthenticatedDataParser(byte[] envelopedData) throws CMSException, IOException
CMSAuthenticatedDataParserback to summary
public CMSAuthenticatedDataParser(byte[] envelopedData, DigestCalculatorProvider digestCalculatorProvider) throws CMSException, IOException
CMSAuthenticatedDataParserback to summary
public CMSAuthenticatedDataParser(InputStream envelopedData) throws CMSException, IOException
CMSAuthenticatedDataParserback to summary
public CMSAuthenticatedDataParser(InputStream envelopedData, DigestCalculatorProvider digestCalculatorProvider) throws CMSException, IOException

Method Detail

getAuthAttrsback to summary
public AttributeTable getAuthAttrs() throws IOException

return a table of the unauthenticated attributes indexed by the OID of the attribute.

getAuthAttrSetback to summary
private ASN1Set getAuthAttrSet() throws IOException
getContentDigestback to summary
public byte[] getContentDigest()

This will only be valid after the content has been read.

Returns:byte[]

the contents of the messageDigest attribute, if available. Null if not present.

getMacback to summary
public byte[] getMac() throws IOException
getMacAlgOIDback to summary
public String getMacAlgOID()

return the object identifier for the mac algorithm.

getMacAlgorithmback to summary
public AlgorithmIdentifier getMacAlgorithm()

Return the MAC algorithm details for the MAC associated with the data in this object.

Returns:AlgorithmIdentifier

AlgorithmIdentifier representing the MAC algorithm.

getMacAlgParamsback to summary
public byte[] getMacAlgParams()

return the ASN.1 encoded encryption algorithm parameters, or null if there aren't any.

getOriginatorInfoback to summary
public OriginatorInformation getOriginatorInfo()

Return the originator information associated with this message if present.

Returns:OriginatorInformation

OriginatorInformation, null if not present.

getRecipientInfosback to summary
public RecipientInformationStore getRecipientInfos()

return a store of the intended recipients for this message

getUnauthAttrsback to summary
public AttributeTable getUnauthAttrs() throws IOException

return a table of the unauthenticated attributes indexed by the OID of the attribute.