Search in sources :

Example 1 with KeyTransRecipientInfo

use of org.bouncycastle.asn1.cms.KeyTransRecipientInfo in project nhin-d by DirectProject.

the class SplitDirectRecipientInformationFactory method createInstance.

/**
	 * {@inheritDoc}
	 */
@Override
public DirectRecipientInformation createInstance(RecipientInformation recipient, SMIMEEnveloped env) {
    try {
        if (recipient == null)
            return null;
        final Field infoField = recipient.getClass().getDeclaredField("_info");
        infoField.setAccessible(true);
        final Object info = infoField.get(recipient);
        if (!(info instanceof KeyTransRecipientInfo)) {
            // fall back to the default if we don't know how to handle this info type
            return new DefaultDirectRecipientInformation(recipient, "");
        }
        final Field encAlgField = CMSEnvelopedData.class.getDeclaredField("encAlg");
        encAlgField.setAccessible(true);
        final Object encAlg = encAlgField.get(env);
        final Field dataField = RecipientInformation.class.getDeclaredField("_data");
        dataField.setAccessible(true);
        final Object data = dataField.get(recipient);
        return new SplitDirectRecipientInformation((KeyTransRecipientInfo) info, (AlgorithmIdentifier) encAlg, (InputStream) data, encProvider, keyEncProvider);
    } catch (Exception e) {
        throw new IllegalStateException("RecipientInformation configuration is not recognized: " + e.getMessage(), e);
    }
}
Also used : Field(java.lang.reflect.Field) KeyTransRecipientInfo(org.bouncycastle.asn1.cms.KeyTransRecipientInfo)

Aggregations

Field (java.lang.reflect.Field)1 KeyTransRecipientInfo (org.bouncycastle.asn1.cms.KeyTransRecipientInfo)1