class BouncyCastleHelper {

    public static void checkCertificateEncodingOrThrowException(Certificate certificate) {
        // OJO...
        try {
            new X509CertificateHolder(certificate.getEncoded());
        } catch (CertificateEncodingException | IOException f) {
            throw new ExceptionConverter(f);
        }
        // ******************************************************************************
    }

    @SuppressWarnings("unchecked")
    public static byte[] getEnvelopedData(PdfArray recipients, List<PdfObject> strings, Certificate certificate,
            Key certificateKey, String certificateKeyProvider) {<FILL_FUNCTION_BODY>}
}

        byte[] envelopedData = null;
        for (PdfObject recipient : recipients.getElements()) {
            strings.remove(recipient);
            try {
                CMSEnvelopedData data = new CMSEnvelopedData(recipient.getBytes());

                final Collection<RecipientInformation> recipientInformations = data.getRecipientInfos().getRecipients();
                for (RecipientInformation recipientInfo : recipientInformations) {
                    if (recipientInfo.getRID().match(certificate)) {
                        // OJO...
                        // https://www.bouncycastle.org/docs/pkixdocs1.5on/org/bouncycastle/cms/CMSEnvelopedData.html
                        Recipient rec = new JceKeyTransEnvelopedRecipient(
                                (PrivateKey) certificateKey)
                                .setProvider(certificateKeyProvider);
                        envelopedData = recipientInfo.getContent(rec);
                        // ******************************************************************************
                        break;
                    }

                }
            } catch (Exception f) {
                throw new ExceptionConverter(f);
            }
        }
        return envelopedData;
    
<no_super_class>