Package org.bouncycastle.mail.smime
Class SMIMEToolkit
java.lang.Object
org.bouncycastle.mail.smime.SMIMEToolkit
A tool kit of common tasks.
-
Constructor Summary
ConstructorsConstructorDescriptionSMIMEToolkit(org.bouncycastle.operator.DigestCalculatorProvider digestCalculatorProvider) Base constructor. -
Method Summary
Modifier and TypeMethodDescriptionjakarta.mail.internet.MimeBodyPartdecrypt(jakarta.mail.internet.MimeBodyPart mimePart, org.bouncycastle.cms.RecipientId recipientId, org.bouncycastle.cms.Recipient recipient) Decrypt the passed in MIME part returning a part representing the decrypted content.jakarta.mail.internet.MimeBodyPartdecrypt(jakarta.mail.internet.MimeMessage message, org.bouncycastle.cms.RecipientId recipientId, org.bouncycastle.cms.Recipient recipient) Decrypt the passed in MIME message returning a part representing the decrypted content.jakarta.mail.internet.MimeBodyPartencrypt(jakarta.mail.internet.MimeBodyPart mimePart, org.bouncycastle.operator.OutputEncryptor contentEncryptor, org.bouncycastle.cms.RecipientInfoGenerator recipientGenerator) Encrypt the passed in MIME part returning a new encrypted MIME part.jakarta.mail.internet.MimeBodyPartencrypt(jakarta.mail.internet.MimeMessage message, org.bouncycastle.operator.OutputEncryptor contentEncryptor, org.bouncycastle.cms.RecipientInfoGenerator recipientGenerator) Encrypt the passed in MIME message returning a new encrypted MIME part.jakarta.mail.internet.MimeBodyPartencrypt(jakarta.mail.internet.MimeMultipart multiPart, org.bouncycastle.operator.OutputEncryptor contentEncryptor, org.bouncycastle.cms.RecipientInfoGenerator recipientGenerator) Encrypt the passed in MIME multi-part returning a new encrypted MIME part.org.bouncycastle.cert.X509CertificateHolderextractCertificate(jakarta.mail.internet.MimeMultipart message, org.bouncycastle.cms.SignerInformation signerInformation) Extract the signer's signing certificate from Multipart message content.org.bouncycastle.cert.X509CertificateHolderextractCertificate(jakarta.mail.Part message, org.bouncycastle.cms.SignerInformation signerInformation) Extract the signer's signing certificate from the message.booleanisEncrypted(jakarta.mail.Part message) Return true if the passed in message (MimeBodyPart or MimeMessage) is encrypted.booleanisSigned(jakarta.mail.internet.MimeMultipart message) Return true if the passed in MimeMultipart is a signed one.booleanisSigned(jakarta.mail.Part message) Return true if the passed in message (MimeBodyPart or MimeMessage) is a signed one.booleanisValidSignature(jakarta.mail.internet.MimeMultipart message, org.bouncycastle.cms.SignerInformationVerifier verifier) Return true if there is a signature on the message that can be verified by verifier..booleanisValidSignature(jakarta.mail.Part message, org.bouncycastle.cms.SignerInformationVerifier verifier) Return true if there is a signature on the message that can be verified by the verifier.jakarta.mail.internet.MimeMultipartsign(jakarta.mail.internet.MimeBodyPart message, org.bouncycastle.cms.SignerInfoGenerator signerInfoGenerator) Produce a signed message in multi-part format with the second part containing a detached signature for the first.jakarta.mail.internet.MimeBodyPartsignEncapsulated(jakarta.mail.internet.MimeBodyPart message, org.bouncycastle.cms.SignerInfoGenerator signerInfoGenerator) Produce a signed message in encapsulated format where the message is encoded in the signature..
-
Constructor Details
-
SMIMEToolkit
public SMIMEToolkit(org.bouncycastle.operator.DigestCalculatorProvider digestCalculatorProvider) Base constructor.- Parameters:
digestCalculatorProvider- provider for any digest calculations required.
-
-
Method Details
-
isEncrypted
public boolean isEncrypted(jakarta.mail.Part message) throws jakarta.mail.MessagingException Return true if the passed in message (MimeBodyPart or MimeMessage) is encrypted.- Parameters:
message- message of interest- Returns:
- true if the message represents an encrypted message, false otherwise.
- Throws:
jakarta.mail.MessagingException- on a message processing issue.
-
isSigned
public boolean isSigned(jakarta.mail.Part message) throws jakarta.mail.MessagingException Return true if the passed in message (MimeBodyPart or MimeMessage) is a signed one.- Parameters:
message- message of interest- Returns:
- true if the message represents a signed message, false otherwise.
- Throws:
jakarta.mail.MessagingException- on a message processing issue.
-
isSigned
public boolean isSigned(jakarta.mail.internet.MimeMultipart message) throws jakarta.mail.MessagingException Return true if the passed in MimeMultipart is a signed one.- Parameters:
message- message of interest- Returns:
- true if the multipart has an attached signature, false otherwise.
- Throws:
jakarta.mail.MessagingException- on a message processing issue.
-
isValidSignature
public boolean isValidSignature(jakarta.mail.Part message, org.bouncycastle.cms.SignerInformationVerifier verifier) throws SMIMEException, jakarta.mail.MessagingException Return true if there is a signature on the message that can be verified by the verifier.- Parameters:
message- a MIME part representing a signed message.verifier- the verifier we want to find a signer for.- Returns:
- true if cert verifies message, false otherwise.
- Throws:
SMIMEException- on a SMIME handling issue.jakarta.mail.MessagingException- on a basic message processing exception
-
isValidSignature
public boolean isValidSignature(jakarta.mail.internet.MimeMultipart message, org.bouncycastle.cms.SignerInformationVerifier verifier) throws SMIMEException, jakarta.mail.MessagingException Return true if there is a signature on the message that can be verified by verifier..- Parameters:
message- a MIME part representing a signed message.verifier- the verifier we want to find a signer for.- Returns:
- true if cert verifies message, false otherwise.
- Throws:
SMIMEException- on a SMIME handling issue.jakarta.mail.MessagingException- on a basic message processing exception
-
extractCertificate
public org.bouncycastle.cert.X509CertificateHolder extractCertificate(jakarta.mail.Part message, org.bouncycastle.cms.SignerInformation signerInformation) throws SMIMEException, jakarta.mail.MessagingException Extract the signer's signing certificate from the message.- Parameters:
message- a MIME part/MIME message representing a signed message.signerInformation- the signer information identifying the signer of interest.- Returns:
- the signing certificate, null if not found.
- Throws:
SMIMEExceptionjakarta.mail.MessagingException
-
extractCertificate
public org.bouncycastle.cert.X509CertificateHolder extractCertificate(jakarta.mail.internet.MimeMultipart message, org.bouncycastle.cms.SignerInformation signerInformation) throws SMIMEException, jakarta.mail.MessagingException Extract the signer's signing certificate from Multipart message content.- Parameters:
message- a MIME Multipart part representing a signed message.signerInformation- the signer information identifying the signer of interest.- Returns:
- the signing certificate, null if not found.
- Throws:
SMIMEExceptionjakarta.mail.MessagingException
-
sign
public jakarta.mail.internet.MimeMultipart sign(jakarta.mail.internet.MimeBodyPart message, org.bouncycastle.cms.SignerInfoGenerator signerInfoGenerator) throws SMIMEException Produce a signed message in multi-part format with the second part containing a detached signature for the first.- Parameters:
message- the message to be signed.signerInfoGenerator- the generator to be used to generate the signature.- Returns:
- the resulting MimeMultipart
- Throws:
SMIMEException- on an exception calculating or creating the signed data.
-
signEncapsulated
public jakarta.mail.internet.MimeBodyPart signEncapsulated(jakarta.mail.internet.MimeBodyPart message, org.bouncycastle.cms.SignerInfoGenerator signerInfoGenerator) throws SMIMEException Produce a signed message in encapsulated format where the message is encoded in the signature..- Parameters:
message- the message to be signed.signerInfoGenerator- the generator to be used to generate the signature.- Returns:
- a BodyPart containing the encapsulated message.
- Throws:
SMIMEException- on an exception calculating or creating the signed data.
-
encrypt
public jakarta.mail.internet.MimeBodyPart encrypt(jakarta.mail.internet.MimeBodyPart mimePart, org.bouncycastle.operator.OutputEncryptor contentEncryptor, org.bouncycastle.cms.RecipientInfoGenerator recipientGenerator) throws SMIMEException Encrypt the passed in MIME part returning a new encrypted MIME part.- Parameters:
mimePart- the part to be encrypted.contentEncryptor- the encryptor to use for the actual message content.recipientGenerator- the generator for the target recipient.- Returns:
- an encrypted MIME part.
- Throws:
SMIMEException- in the event of an exception creating the encrypted part.
-
encrypt
public jakarta.mail.internet.MimeBodyPart encrypt(jakarta.mail.internet.MimeMultipart multiPart, org.bouncycastle.operator.OutputEncryptor contentEncryptor, org.bouncycastle.cms.RecipientInfoGenerator recipientGenerator) throws SMIMEException, jakarta.mail.MessagingException Encrypt the passed in MIME multi-part returning a new encrypted MIME part.- Parameters:
multiPart- the multi-part to be encrypted.contentEncryptor- the encryptor to use for the actual message content.recipientGenerator- the generator for the target recipient.- Returns:
- an encrypted MIME part.
- Throws:
SMIMEException- in the event of an exception creating the encrypted part.jakarta.mail.MessagingException
-
encrypt
public jakarta.mail.internet.MimeBodyPart encrypt(jakarta.mail.internet.MimeMessage message, org.bouncycastle.operator.OutputEncryptor contentEncryptor, org.bouncycastle.cms.RecipientInfoGenerator recipientGenerator) throws SMIMEException Encrypt the passed in MIME message returning a new encrypted MIME part.- Parameters:
message- the multi-part to be encrypted.contentEncryptor- the encryptor to use for the actual message content.recipientGenerator- the generator for the target recipient.- Returns:
- an encrypted MIME part.
- Throws:
SMIMEException- in the event of an exception creating the encrypted part.
-
decrypt
public jakarta.mail.internet.MimeBodyPart decrypt(jakarta.mail.internet.MimeBodyPart mimePart, org.bouncycastle.cms.RecipientId recipientId, org.bouncycastle.cms.Recipient recipient) throws SMIMEException, jakarta.mail.MessagingException Decrypt the passed in MIME part returning a part representing the decrypted content.- Parameters:
mimePart- the part containing the encrypted data.recipientId- the recipient id in the date to be matched.recipient- the recipient to be used if a match is found.- Returns:
- a MIME part containing the decrypted content or null if the recipientId cannot be matched.
- Throws:
SMIMEException- on an exception doing the decryption.jakarta.mail.MessagingException- on an exception parsing the message,
-
decrypt
public jakarta.mail.internet.MimeBodyPart decrypt(jakarta.mail.internet.MimeMessage message, org.bouncycastle.cms.RecipientId recipientId, org.bouncycastle.cms.Recipient recipient) throws SMIMEException, jakarta.mail.MessagingException Decrypt the passed in MIME message returning a part representing the decrypted content.- Parameters:
message- the message containing the encrypted data.recipientId- the recipient id in the date to be matched.recipient- the recipient to be used if a match is found.- Returns:
- a MIME part containing the decrypted content, or null if the recipientId cannot be matched.
- Throws:
SMIMEException- on an exception doing the decryption.jakarta.mail.MessagingException- on an exception parsing the message,
-