FileDocCategorySizeDatePackage
SMIMEEnvelopedGenerator.javaAPI DocBouncy Castle Crypto API 1.41 (Java 1.5)16206Wed Oct 01 10:55:28 BST 2008org.bouncycastle.mail.smime

SMIMEEnvelopedGenerator

public class SMIMEEnvelopedGenerator extends SMIMEGenerator
General class for generating a pkcs7-mime message. A simple example of usage.
SMIMEEnvelopedGenerator fact = new SMIMEEnvelopedGenerator();

fact.addKeyTransRecipient(cert);

MimeBodyPart smime = fact.generate(content, algorithm, "BC");
Note: Most clients expect the MimeBodyPart to be in a MimeMultipart when it's sent.

Fields Summary
public static final String
DES_EDE3_CBC
public static final String
RC2_CBC
public static final String
IDEA_CBC
public static final String
CAST5_CBC
public static final String
AES128_CBC
public static final String
AES192_CBC
public static final String
AES256_CBC
public static final String
CAMELLIA128_CBC
public static final String
CAMELLIA192_CBC
public static final String
CAMELLIA256_CBC
public static final String
SEED_CBC
public static final String
DES_EDE3_WRAP
public static final String
AES128_WRAP
public static final String
AES256_WRAP
public static final String
CAMELLIA128_WRAP
public static final String
CAMELLIA192_WRAP
public static final String
CAMELLIA256_WRAP
public static final String
SEED_WRAP
public static final String
ECDH_SHA1KDF
private static final String
ENCRYPTED_CONTENT_TYPE
private EnvelopedGenerator
fact
Constructors Summary
public SMIMEEnvelopedGenerator()
base constructor


    
    
        MailcapCommandMap mc = (MailcapCommandMap)CommandMap.getDefaultCommandMap();

        mc.addMailcap("application/pkcs7-mime;; x-java-content-handler=org.bouncycastle.mail.smime.handlers.pkcs7_mime");
        mc.addMailcap("application/x-pkcs7-mime;; x-java-content-handler=org.bouncycastle.mail.smime.handlers.x_pkcs7_mime");

        CommandMap.setDefaultCommandMap(mc);
    
        fact = new EnvelopedGenerator();
    
Methods Summary
public voidaddKEKRecipient(javax.crypto.SecretKey key, byte[] keyIdentifier)
add a KEK recipient.

        fact.addKEKRecipient(key, keyIdentifier);
    
public voidaddKeyAgreementRecipient(java.lang.String agreementAlgorithm, java.security.PrivateKey senderPrivateKey, java.security.PublicKey senderPublicKey, java.security.cert.X509Certificate recipientCert, java.lang.String cekWrapAlgorithm, java.lang.String provider)
Add a key agreement based recipient.

param
senderPrivateKey private key to initialise sender side of agreement with.
param
senderPublicKey sender public key to include with message.
param
recipientCert recipient's public key certificate.
param
cekWrapAlgorithm OID for key wrapping algorithm to use.
param
provider provider to use for the agreement calculation.

        fact.addKeyAgreementRecipient(agreementAlgorithm, senderPrivateKey, senderPublicKey, recipientCert, cekWrapAlgorithm, provider);
    
public voidaddKeyAgreementRecipient(java.lang.String agreementAlgorithm, java.security.PrivateKey senderPrivateKey, java.security.PublicKey senderPublicKey, java.security.cert.X509Certificate recipientCert, java.lang.String cekWrapAlgorithm, java.security.Provider provider)
Add a key agreement based recipient.

param
senderPrivateKey private key to initialise sender side of agreement with.
param
senderPublicKey sender public key to include with message.
param
recipientCert recipient's public key certificate.
param
cekWrapAlgorithm OID for key wrapping algorithm to use.
param
provider provider to use for the agreement calculation.

        fact.addKeyAgreementRecipient(agreementAlgorithm, senderPrivateKey, senderPublicKey, recipientCert, cekWrapAlgorithm, provider);
    
public voidaddKeyTransRecipient(java.security.cert.X509Certificate cert)
add a recipient.

        fact.addKeyTransRecipient(cert);
    
public voidaddKeyTransRecipient(java.security.PublicKey key, byte[] subKeyId)
add a recipient - note: this will only work on V3 and later clients.

param
key the recipient's public key
param
subKeyId the subject key id for the recipient's public key

        fact.addKeyTransRecipient(key, subKeyId);
    
public javax.mail.internet.MimeBodyPartgenerate(javax.mail.internet.MimeBodyPart content, java.lang.String encryptionOID, java.security.Provider provider)
generate an enveloped object that contains an SMIME Enveloped object using the given provider.

        return make(makeContentBodyPart(content), encryptionOID, 0, provider);
    
public javax.mail.internet.MimeBodyPartgenerate(javax.mail.internet.MimeMessage message, java.lang.String encryptionOID, java.lang.String provider)
generate an enveloped object that contains an SMIME Enveloped object using the given provider from the contents of the passed in message

        return generate(message, encryptionOID, SMIMEUtil.getProvider(provider));
    
public javax.mail.internet.MimeBodyPartgenerate(javax.mail.internet.MimeMessage message, java.lang.String encryptionOID, java.security.Provider provider)
generate an enveloped object that contains an SMIME Enveloped object using the given provider from the contents of the passed in message

        try
        {
            message.saveChanges();      // make sure we're up to date.
        }
        catch (MessagingException e)
        {
            throw new SMIMEException("unable to save message", e);
        }
                        
        return make(makeContentBodyPart(message), encryptionOID, 0, provider);
    
public javax.mail.internet.MimeBodyPartgenerate(javax.mail.internet.MimeBodyPart content, java.lang.String encryptionOID, int keySize, java.lang.String provider)
generate an enveloped object that contains an SMIME Enveloped object using the given provider. The size of the encryption key is determined by keysize.

        return generate(content, encryptionOID, keySize, SMIMEUtil.getProvider(provider));
    
public javax.mail.internet.MimeBodyPartgenerate(javax.mail.internet.MimeBodyPart content, java.lang.String encryptionOID, int keySize, java.security.Provider provider)
generate an enveloped object that contains an SMIME Enveloped object using the given provider. The size of the encryption key is determined by keysize.

        return make(makeContentBodyPart(content), encryptionOID, keySize, provider);
    
public javax.mail.internet.MimeBodyPartgenerate(javax.mail.internet.MimeMessage message, java.lang.String encryptionOID, int keySize, java.lang.String provider)
generate an enveloped object that contains an SMIME Enveloped object using the given provider from the contents of the passed in message. The size of the encryption key used to protect the message is determined by keysize.

        return generate(message, encryptionOID, keySize, SMIMEUtil.getProvider(provider));
    
public javax.mail.internet.MimeBodyPartgenerate(javax.mail.internet.MimeMessage message, java.lang.String encryptionOID, int keySize, java.security.Provider provider)
generate an enveloped object that contains an SMIME Enveloped object using the given provider from the contents of the passed in message. The size of the encryption key used to protect the message is determined by keysize.

        try
        {
            message.saveChanges();      // make sure we're up to date.
        }
        catch (MessagingException e)
        {
            throw new SMIMEException("unable to save message", e);
        }
                        
        return make(makeContentBodyPart(message), encryptionOID, keySize, provider);
    
public javax.mail.internet.MimeBodyPartgenerate(javax.mail.internet.MimeBodyPart content, java.lang.String encryptionOID, java.lang.String provider)
generate an enveloped object that contains an SMIME Enveloped object using the given provider.

        return make(makeContentBodyPart(content), encryptionOID, 0, SMIMEUtil.getProvider(provider));
    
private javax.mail.internet.MimeBodyPartmake(javax.mail.internet.MimeBodyPart content, java.lang.String encryptionOID, int keySize, java.security.Provider provider)
if we get here we expect the Mime body part to be well defined.

        //
        // check the base algorithm and provider is available
        //
        createSymmetricKeyGenerator(encryptionOID, provider);
                
        try
        {  
            MimeBodyPart data = new MimeBodyPart();
        
            data.setContent(new ContentEncryptor(content, encryptionOID, keySize, provider), ENCRYPTED_CONTENT_TYPE);
            data.addHeader("Content-Type", ENCRYPTED_CONTENT_TYPE);
            data.addHeader("Content-Disposition", "attachment; filename=\"smime.p7m\"");
            data.addHeader("Content-Description", "S/MIME Encrypted Message");
            data.addHeader("Content-Transfer-Encoding", encoding);
    
            return data;
        }
        catch (MessagingException e)
        {
            throw new SMIMEException("exception putting multi-part together.", e);
        }
    
public voidsetBerEncodeRecipients(boolean berEncodeRecipientSet)
Use a BER Set to store the recipient information

        fact.setBEREncodeRecipients(berEncodeRecipientSet);