use of org.bouncycastle.mail.smime.SMIMEEnvelopedGenerator in project nhin-d by DirectProject.
the class SMIMECryptographerImpl method createEncryptedEnvelope.
private MimeBodyPart createEncryptedEnvelope(MimeBodyPart bodyPart, Collection<X509Certificate> encryptingCertificates) {
if (bodyPart == null || encryptingCertificates == null || encryptingCertificates.size() == 0) {
throw new IllegalArgumentException();
}
if (LOGGER.isDebugEnabled()) {
writePreEncypt(EntitySerializer.Default.serializeToBytes(bodyPart));
}
SMIMEEnvelopedGenerator gen = new SMIMEEnvelopedGenerator();
for (X509Certificate cert : encryptingCertificates) gen.addKeyTransRecipient(cert);
MimeBodyPart retVal = null;
try {
final String encryAlgOID = this.m_encryptionAlgorithm.getOID();
retVal = gen.generate(bodyPart, encryAlgOID, CryptoExtensions.getJCEProviderNameForTypeAndAlgorithm("Cipher", encryAlgOID));
} catch (Exception e) {
throw new MimeException(MimeError.Unexpected, e);
}
return retVal;
}
Aggregations