Example usage for org.bouncycastle.cms CMSEnvelopedData getRecipientInfos

List of usage examples for org.bouncycastle.cms CMSEnvelopedData getRecipientInfos

Introduction

In this page you can find the example usage for org.bouncycastle.cms CMSEnvelopedData getRecipientInfos.

Prototype

public RecipientInformationStore getRecipientInfos() 

Source Link

Document

return a store of the intended recipients for this message

Usage

From source file:org.xipki.pki.scep.message.EnvelopedDataDecryptor.java

License:Open Source License

public byte[] decrypt(final CMSEnvelopedData envData) throws MessageDecodingException {
    ParamUtil.requireNonNull("envData", envData);
    final RecipientInformationStore recipientInfos = envData.getRecipientInfos();
    RecipientInformation recipientInfo = null;
    EnvelopedDataDecryptorInstance decryptor = null;
    for (EnvelopedDataDecryptorInstance m : decryptors) {
        recipientInfo = recipientInfos.get(m.getRecipientId());
        if (recipientInfo != null) {
            decryptor = m;//from w  ww  . ja  v a 2  s  .co  m
            break;
        }
    }

    if (recipientInfo == null || decryptor == null) {
        throw new MessageDecodingException("missing expected key transfer recipient");
    }

    try {
        return recipientInfo.getContent(decryptor.getRecipient());
    } catch (CMSException ex) {
        throw new MessageDecodingException("could not decrypt the envelopedData");
    }
}