Example usage for org.bouncycastle.cms.jcajce JceKeyTransRecipientInfoGenerator setProvider

List of usage examples for org.bouncycastle.cms.jcajce JceKeyTransRecipientInfoGenerator setProvider

Introduction

In this page you can find the example usage for org.bouncycastle.cms.jcajce JceKeyTransRecipientInfoGenerator setProvider.

Prototype

public JceKeyTransRecipientInfoGenerator setProvider(Provider provider) 

Source Link

Usage

From source file:mitm.common.security.smime.SMIMEBuilderImpl.java

License:Open Source License

@Override
public void addRecipient(X509Certificate certificate, SMIMERecipientMode mode) throws SMIMEBuilderException {
    Check.notNull(certificate, "certificate");

    try {/*from ww  w.j a v a 2 s .c  o m*/
        byte[] subjectKeyIdentifier = X509CertificateInspector.getSubjectKeyIdentifier(certificate);

        if ((mode == SMIMERecipientMode.SUBJECT_KEY_ID_IF_AVAILABLE || mode == SMIMERecipientMode.BOTH)
                && subjectKeyIdentifier != null) {
            PublicKey publicKey = certificate.getPublicKey();

            JceKeyTransRecipientInfoGenerator recipientInfoGenerator = new JceKeyTransRecipientInfoGenerator(
                    subjectKeyIdentifier, publicKey);

            recipientInfoGenerator.setProvider(nonSensitiveProvider);

            envelopedGenerator.addRecipientInfoGenerator(recipientInfoGenerator);
        }

        if (mode == SMIMERecipientMode.ISSUER_SERIAL || mode == SMIMERecipientMode.BOTH
                || subjectKeyIdentifier == null) {
            JceKeyTransRecipientInfoGenerator recipientInfoGenerator = new JceKeyTransRecipientInfoGenerator(
                    certificate);

            recipientInfoGenerator.setProvider(nonSensitiveProvider);

            envelopedGenerator.addRecipientInfoGenerator(recipientInfoGenerator);
        }
    } catch (IOException e) {
        throw new SMIMEBuilderException(e);
    } catch (CertificateEncodingException e) {
        throw new SMIMEBuilderException(e);
    }
}

From source file:net.markenwerk.utils.mail.smime.SmimeUtil.java

License:Open Source License

private static SMIMEEnvelopedGenerator prepareGenerator(X509Certificate certificate)
        throws CertificateEncodingException {
    JceKeyTransRecipientInfoGenerator infoGenerator = new JceKeyTransRecipientInfoGenerator(certificate);
    infoGenerator.setProvider(BouncyCastleProvider.PROVIDER_NAME);
    SMIMEEnvelopedGenerator generator = new SMIMEEnvelopedGenerator();
    generator.addRecipientInfoGenerator(infoGenerator);
    return generator;
}