
org.bouncycastle.mail.smime.SMIMEEnvelopedUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bcmail-jdk18on Show documentation
Show all versions of bcmail-jdk18on Show documentation
The Bouncy Castle Java S/MIME APIs for handling S/MIME protocols. This jar contains S/MIME APIs for JDK 1.8 and up. The APIs can be used in conjunction with a JCE/JCA provider such as the one provided with the Bouncy Castle Cryptography APIs. The JavaMail API and the Java activation framework will also be needed.
The newest version!
package org.bouncycastle.mail.smime;
import java.util.HashSet;
import java.util.Set;
import javax.mail.MessagingException;
import javax.mail.internet.MimeBodyPart;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.nist.NISTObjectIdentifiers;
import org.bouncycastle.cms.CMSException;
import org.bouncycastle.cms.RecipientInformationStore;
public class SMIMEEnvelopedUtil
{
private static Set authOIDs = new HashSet();
static
{
authOIDs.add(NISTObjectIdentifiers.id_aes128_GCM);
authOIDs.add(NISTObjectIdentifiers.id_aes128_GCM);
authOIDs.add(NISTObjectIdentifiers.id_aes128_GCM);
}
/**
* Parse the passed in MimeMessage extracting the RecipientInfos from it.
*
* @param message the message to be parsed.
* @return the RecipientInformation store for the passed in message.
* @throws MessagingException
* @throws CMSException
*/
public static RecipientInformationStore getRecipientInfos(MimeBodyPart message) throws MessagingException, CMSException
{
if(message.getContentType().equals(SMIMEAuthEnvelopedGenerator.AUTH_ENVELOPED_DATA_CONTENT_TYPE))
{
return new SMIMEAuthEnveloped(message).getRecipientInfos();
}
return new SMIMEEnveloped(message).getRecipientInfos();
}
/**
* Utility method which will return an SMIMEEnvelopedGenerator or an
* SMIMEAuthEnvelopedGenerator as appropriate for the algorithm OID passed in.
*
* @param algorithm algorithm OID
* @return a SMIME Enveloped Generator class.
*/
public static SMIMEEnvelopedGenerator createGenerator(ASN1ObjectIdentifier algorithm)
{
if (authOIDs.contains(algorithm))
{
return new SMIMEAuthEnvelopedGenerator();
}
return new SMIMEEnvelopedGenerator();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy