Search in sources :

Example 1 with SMIMEEnvelopedGenerator

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;
}
Also used : SMIMEEnvelopedGenerator(org.bouncycastle.mail.smime.SMIMEEnvelopedGenerator) MimeException(org.nhindirect.stagent.mail.MimeException) ASN1OctetString(org.bouncycastle.asn1.ASN1OctetString) MimeBodyPart(javax.mail.internet.MimeBodyPart) X509Certificate(java.security.cert.X509Certificate) MessagingException(javax.mail.MessagingException) MimeException(org.nhindirect.stagent.mail.MimeException) NHINDException(org.nhindirect.stagent.NHINDException) ParseException(javax.mail.internet.ParseException) IOException(java.io.IOException) SignatureValidationException(org.nhindirect.stagent.SignatureValidationException)

Aggregations

IOException (java.io.IOException)1 X509Certificate (java.security.cert.X509Certificate)1 MessagingException (javax.mail.MessagingException)1 MimeBodyPart (javax.mail.internet.MimeBodyPart)1 ParseException (javax.mail.internet.ParseException)1 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)1 SMIMEEnvelopedGenerator (org.bouncycastle.mail.smime.SMIMEEnvelopedGenerator)1 NHINDException (org.nhindirect.stagent.NHINDException)1 SignatureValidationException (org.nhindirect.stagent.SignatureValidationException)1 MimeException (org.nhindirect.stagent.mail.MimeException)1