SMIMEEnvelopedGeneratorpublic 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 void | addKEKRecipient(javax.crypto.SecretKey key, byte[] keyIdentifier)add a KEK recipient.
fact.addKEKRecipient(key, keyIdentifier);
| public void | addKeyAgreementRecipient(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.
fact.addKeyAgreementRecipient(agreementAlgorithm, senderPrivateKey, senderPublicKey, recipientCert, cekWrapAlgorithm, provider);
| public void | addKeyAgreementRecipient(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.
fact.addKeyAgreementRecipient(agreementAlgorithm, senderPrivateKey, senderPublicKey, recipientCert, cekWrapAlgorithm, provider);
| public void | addKeyTransRecipient(java.security.cert.X509Certificate cert)add a recipient.
fact.addKeyTransRecipient(cert);
| public void | addKeyTransRecipient(java.security.PublicKey key, byte[] subKeyId)add a recipient - note: this will only work on V3 and later clients.
fact.addKeyTransRecipient(key, subKeyId);
| public javax.mail.internet.MimeBodyPart | generate(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.MimeBodyPart | generate(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.MimeBodyPart | generate(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.MimeBodyPart | generate(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.MimeBodyPart | generate(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.MimeBodyPart | generate(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.MimeBodyPart | generate(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.MimeBodyPart | generate(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.MimeBodyPart | make(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 void | setBerEncodeRecipients(boolean berEncodeRecipientSet)Use a BER Set to store the recipient information
fact.setBEREncodeRecipients(berEncodeRecipientSet);
|
|