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.
| Modifier and Type | Field 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 |
| Access | Constructor and Description |
|---|---|
| public | |
| public | |
| public | |
| public | CMSAuthenticatedDataParser(InputStream envelopedData, DigestCalculatorProvider digestCalculatorProvider)
|
| Modifier and Type | Method and Description |
|---|---|
| public AttributeTable | |
| private ASN1Set | |
| public byte[] | Returns: the contents of the messageDigest attribute, if available. Null if not present.This will only be valid after the content has been read. |
| public byte[] | |
| public String | |
| public AlgorithmIdentifier | Returns: AlgorithmIdentifier representing the MAC algorithm.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.Return the originator information associated with this message if present. |
| public RecipientInformationStore | |
| public AttributeTable | getUnauthAttrs()
return a table of the unauthenticated attributes indexed by the OID of the attribute. |
| authAttrNotRead | back to summary |
|---|---|
| private boolean authAttrNotRead | |
| authAttrs | back to summary |
|---|---|
| private AttributeTable authAttrs | |
| authAttrSet | back to summary |
|---|---|
| private ASN1Set authAttrSet | |
| authData | back to summary |
|---|---|
| pack-priv AuthenticatedDataParser authData | |
| mac | back to summary |
|---|---|
| private byte[] mac | |
| macAlg | back to summary |
|---|---|
| private AlgorithmIdentifier macAlg | |
| originatorInfo | back to summary |
|---|---|
| private OriginatorInformation originatorInfo | |
| recipientInfoStore | back to summary |
|---|---|
| pack-priv RecipientInformationStore recipientInfoStore | |
| secureReadable | back to summary |
|---|---|
| private CMSSecureReadable secureReadable | |
| unauthAttrNotRead | back to summary |
|---|---|
| private boolean unauthAttrNotRead | |
| unauthAttrs | back to summary |
|---|---|
| private AttributeTable unauthAttrs | |
| CMSAuthenticatedDataParser | back to summary |
|---|---|
| public CMSAuthenticatedDataParser(byte[] envelopedData) throws CMSException, IOException | |
| CMSAuthenticatedDataParser | back to summary |
|---|---|
| public CMSAuthenticatedDataParser(byte[] envelopedData, DigestCalculatorProvider digestCalculatorProvider) throws CMSException, IOException | |
| CMSAuthenticatedDataParser | back to summary |
|---|---|
| public CMSAuthenticatedDataParser(InputStream envelopedData) throws CMSException, IOException | |
| CMSAuthenticatedDataParser | back to summary |
|---|---|
| public CMSAuthenticatedDataParser(InputStream envelopedData, DigestCalculatorProvider digestCalculatorProvider) throws CMSException, IOException | |
| getAuthAttrs | back to summary |
|---|---|
| public AttributeTable getAuthAttrs() throws IOException return a table of the unauthenticated attributes indexed by the OID of the attribute. | |
| getAuthAttrSet | back to summary |
|---|---|
| private ASN1Set getAuthAttrSet() throws IOException | |
| getContentDigest | back to summary |
|---|---|
| public byte[] getContentDigest() This will only be valid after the content has been read.
| |
| getMac | back to summary |
|---|---|
| public byte[] getMac() throws IOException | |
| getMacAlgOID | back to summary |
|---|---|
| public String getMacAlgOID() return the object identifier for the mac algorithm. | |
| getMacAlgorithm | back to summary |
|---|---|
| public AlgorithmIdentifier getMacAlgorithm() Return the MAC algorithm details for the MAC associated with the data in this object.
| |
| getMacAlgParams | back to summary |
|---|---|
| public byte[] getMacAlgParams() return the ASN.1 encoded encryption algorithm parameters, or null if there aren't any. | |
| getOriginatorInfo | back to summary |
|---|---|
| public OriginatorInformation getOriginatorInfo() Return the originator information associated with this message if present.
| |
| getRecipientInfos | back to summary |
|---|---|
| public RecipientInformationStore getRecipientInfos() return a store of the intended recipients for this message | |
| getUnauthAttrs | back to summary |
|---|---|
| public AttributeTable getUnauthAttrs() throws IOException return a table of the unauthenticated attributes indexed by the OID of the attribute. | |