List of usage examples for org.bouncycastle.cms.jcajce JceKeyTransRecipientInfoGenerator setProvider
public JceKeyTransRecipientInfoGenerator setProvider(Provider provider)
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; }