Top Description Fields Constructors Methods
org.bouncycastle.mail.smime

public Class SMIMEToolkit

extends Object
Class Inheritance
Imports
java.io.IOException, java.util.ArrayList, .Collection, .Iterator, .List, javax.mail.MessagingException, .Part, javax.mail.internet.MimeBodyPart, .MimeMessage, .MimeMultipart, org.bouncycastle.cert.X509CertificateHolder, org.bouncycastle.cms.CMSException, .Recipient, .RecipientId, .RecipientInfoGenerator, .RecipientInformation, .RecipientInformationStore, .SignerId, .SignerInfoGenerator, .SignerInformation, .SignerInformationVerifier, org.bouncycastle.operator.DigestCalculatorProvider, .OutputEncryptor, org.bouncycastle.util.CollectionStore

A tool kit of common tasks.

Field Summary

Modifier and TypeField and Description
private final DigestCalculatorProvider

Constructor Summary

AccessConstructor and Description
public
SMIMEToolkit(DigestCalculatorProvider
provider for any digest calculations required.
digestCalculatorProvider
)

Base constructor.

Method Summary

Modifier and TypeMethod and Description
public MimeBodyPart

Returns:

a MIME part containing the decrypted content or null if the recipientId cannot be matched.
decrypt
(MimeBodyPart
the part containing the encrypted data.
mimePart
,
RecipientId
the recipient id in the date to be matched.
recipientId
,
Recipient
the recipient to be used if a match is found.
recipient
)

Decrypt the passed in MIME part returning a part representing the decrypted content.

public MimeBodyPart

Returns:

a MIME part containing the decrypted content, or null if the recipientId cannot be matched.
decrypt
(MimeMessage
the message containing the encrypted data.
message
,
RecipientId
the recipient id in the date to be matched.
recipientId
,
Recipient
the recipient to be used if a match is found.
recipient
)

Decrypt the passed in MIME message returning a part representing the decrypted content.

public MimeBodyPart

Returns:

an encrypted MIME part.
encrypt
(MimeBodyPart
the part to be encrypted.
mimePart
,
OutputEncryptor
the encryptor to use for the actual message content.
contentEncryptor
,
RecipientInfoGenerator
the generator for the target recipient.
recipientGenerator
)

Encrypt the passed in MIME part returning a new encrypted MIME part.

public MimeBodyPart

Returns:

an encrypted MIME part.
encrypt
(MimeMultipart
the multi-part to be encrypted.
multiPart
,
OutputEncryptor
the encryptor to use for the actual message content.
contentEncryptor
,
RecipientInfoGenerator
the generator for the target recipient.
recipientGenerator
)

Encrypt the passed in MIME multi-part returning a new encrypted MIME part.

public MimeBodyPart

Returns:

an encrypted MIME part.
encrypt
(MimeMessage
the multi-part to be encrypted.
message
,
OutputEncryptor
the encryptor to use for the actual message content.
contentEncryptor
,
RecipientInfoGenerator
the generator for the target recipient.
recipientGenerator
)

Encrypt the passed in MIME message returning a new encrypted MIME part.

public X509CertificateHolder

Returns:

the signing certificate, null if not found.
extractCertificate
(Part
a MIME part/MIME message representing a signed message.
message
,
SignerInformation
the signer information identifying the signer of interest.
signerInformation
)

Extract the signer's signing certificate from the message.

public X509CertificateHolder

Returns:

the signing certificate, null if not found.
extractCertificate
(MimeMultipart
a MIME Multipart part representing a signed message.
message
,
SignerInformation
the signer information identifying the signer of interest.
signerInformation
)

Extract the signer's signing certificate from Multipart message content.

private static MimeBodyPart
private static SMIMESignedGenerator
private static X509CertificateHolder
private boolean
public boolean

Returns:

true if the message represents an encrypted message, false otherwise.
isEncrypted
(Part
message of interest
message
)

Return true if the passed in message (MimeBodyPart or MimeMessage) is encrypted.

public boolean

Returns:

true if the message represents a signed message, false otherwise.
isSigned
(Part
message of interest
message
)

Return true if the passed in message (MimeBodyPart or MimeMessage) is a signed one.

public boolean

Returns:

true if the multipart has an attached signature, false otherwise.
isSigned
(MimeMultipart
message of interest
message
)

Return true if the passed in MimeMultipart is a signed one.

public boolean

Returns:

true if cert verifies message, false otherwise.
isValidSignature
(Part
a MIME part representing a signed message.
message
,
SignerInformationVerifier
the verifier we want to find a signer for.
verifier
)

Return true if there is a signature on the message that can be verified by the verifier.

public boolean

Returns:

true if cert verifies message, false otherwise.
isValidSignature
(MimeMultipart
a MIME part representing a signed message.
message
,
SignerInformationVerifier
the verifier we want to find a signer for.
verifier
)

Return true if there is a signature on the message that can be verified by verifier..

public MimeMultipart

Returns:

the resulting MimeMultipart
sign
(MimeBodyPart
the message to be signed.
message
,
SignerInfoGenerator
the generator to be used to generate the signature.
signerInfoGenerator
)

Produce a signed message in multi-part format with the second part containing a detached signature for the first.

public MimeBodyPart

Returns:

a BodyPart containing the encapsulated message.
signEncapsulated
(MimeBodyPart
the message to be signed.
message
,
SignerInfoGenerator
the generator to be used to generate the signature.
signerInfoGenerator
)

Produce a signed message in encapsulated format where the message is encoded in the signature..

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

digestCalculatorProviderback to summary
private final DigestCalculatorProvider digestCalculatorProvider

Constructor Detail

SMIMEToolkitback to summary
public SMIMEToolkit(DigestCalculatorProvider digestCalculatorProvider)

Base constructor.

Parameters
digestCalculatorProvider:DigestCalculatorProvider

provider for any digest calculations required.

Method Detail

decryptback to summary
public MimeBodyPart decrypt(MimeBodyPart mimePart, RecipientId recipientId, Recipient recipient) throws SMIMEException, MessagingException

Decrypt the passed in MIME part returning a part representing the decrypted content.

Parameters
mimePart:MimeBodyPart

the part containing the encrypted data.

recipientId:RecipientId

the recipient id in the date to be matched.

recipient:Recipient

the recipient to be used if a match is found.

Returns:MimeBodyPart

a MIME part containing the decrypted content or null if the recipientId cannot be matched.

Exceptions
SMIMEException:
on an exception doing the decryption.
MessagingException:
on an exception parsing the message,
decryptback to summary
public MimeBodyPart decrypt(MimeMessage message, RecipientId recipientId, Recipient recipient) throws SMIMEException, MessagingException

Decrypt the passed in MIME message returning a part representing the decrypted content.

Parameters
message:MimeMessage

the message containing the encrypted data.

recipientId:RecipientId

the recipient id in the date to be matched.

recipient:Recipient

the recipient to be used if a match is found.

Returns:MimeBodyPart

a MIME part containing the decrypted content, or null if the recipientId cannot be matched.

Exceptions
SMIMEException:
on an exception doing the decryption.
MessagingException:
on an exception parsing the message,
encryptback to summary
public MimeBodyPart encrypt(MimeBodyPart mimePart, OutputEncryptor contentEncryptor, RecipientInfoGenerator recipientGenerator) throws SMIMEException

Encrypt the passed in MIME part returning a new encrypted MIME part.

Parameters
mimePart:MimeBodyPart

the part to be encrypted.

contentEncryptor:OutputEncryptor

the encryptor to use for the actual message content.

recipientGenerator:RecipientInfoGenerator

the generator for the target recipient.

Returns:MimeBodyPart

an encrypted MIME part.

Exceptions
SMIMEException:
in the event of an exception creating the encrypted part.
encryptback to summary
public MimeBodyPart encrypt(MimeMultipart multiPart, OutputEncryptor contentEncryptor, RecipientInfoGenerator recipientGenerator) throws SMIMEException, MessagingException

Encrypt the passed in MIME multi-part returning a new encrypted MIME part.

Parameters
multiPart:MimeMultipart

the multi-part to be encrypted.

contentEncryptor:OutputEncryptor

the encryptor to use for the actual message content.

recipientGenerator:RecipientInfoGenerator

the generator for the target recipient.

Returns:MimeBodyPart

an encrypted MIME part.

Exceptions
SMIMEException:
in the event of an exception creating the encrypted part.
encryptback to summary
public MimeBodyPart encrypt(MimeMessage message, OutputEncryptor contentEncryptor, RecipientInfoGenerator recipientGenerator) throws SMIMEException

Encrypt the passed in MIME message returning a new encrypted MIME part.

Parameters
message:MimeMessage

the multi-part to be encrypted.

contentEncryptor:OutputEncryptor

the encryptor to use for the actual message content.

recipientGenerator:RecipientInfoGenerator

the generator for the target recipient.

Returns:MimeBodyPart

an encrypted MIME part.

Exceptions
SMIMEException:
in the event of an exception creating the encrypted part.
extractCertificateback to summary
public X509CertificateHolder extractCertificate(Part message, SignerInformation signerInformation) throws SMIMEException, MessagingException

Extract the signer's signing certificate from the message.

Parameters
message:Part

a MIME part/MIME message representing a signed message.

signerInformation:SignerInformation

the signer information identifying the signer of interest.

Returns:X509CertificateHolder

the signing certificate, null if not found.

extractCertificateback to summary
public X509CertificateHolder extractCertificate(MimeMultipart message, SignerInformation signerInformation) throws SMIMEException, MessagingException

Extract the signer's signing certificate from Multipart message content.

Parameters
message:MimeMultipart

a MIME Multipart part representing a signed message.

signerInformation:SignerInformation

the signer information identifying the signer of interest.

Returns:X509CertificateHolder

the signing certificate, null if not found.

getMimeBodyPartback to summary
private static MimeBodyPart getMimeBodyPart(RecipientId recipientId, Recipient recipient, SMIMEEnvelopedParser m) throws SMIMEException, CMSException
getSMIMESignedGeneratorback to summary
private static SMIMESignedGenerator getSMIMESignedGenerator(SignerInfoGenerator signerInfoGenerator)
getX509CertificateHolderback to summary
private static X509CertificateHolder getX509CertificateHolder(SMIMESignedParser s, SignerInformation signerInformation) throws CMSException
isAtLeastOneValidSignerback to summary
private boolean isAtLeastOneValidSigner(SMIMESignedParser s, SignerInformationVerifier verifier) throws CMSException
isEncryptedback to summary
public boolean isEncrypted(Part message) throws MessagingException

Return true if the passed in message (MimeBodyPart or MimeMessage) is encrypted.

Parameters
message:Part

message of interest

Returns:boolean

true if the message represents an encrypted message, false otherwise.

Exceptions
MessagingException:
on a message processing issue.
isSignedback to summary
public boolean isSigned(Part message) throws MessagingException

Return true if the passed in message (MimeBodyPart or MimeMessage) is a signed one.

Parameters
message:Part

message of interest

Returns:boolean

true if the message represents a signed message, false otherwise.

Exceptions
MessagingException:
on a message processing issue.
isSignedback to summary
public boolean isSigned(MimeMultipart message) throws MessagingException

Return true if the passed in MimeMultipart is a signed one.

Parameters
message:MimeMultipart

message of interest

Returns:boolean

true if the multipart has an attached signature, false otherwise.

Exceptions
MessagingException:
on a message processing issue.
isValidSignatureback to summary
public boolean isValidSignature(Part message, SignerInformationVerifier verifier) throws SMIMEException, MessagingException

Return true if there is a signature on the message that can be verified by the verifier.

Parameters
message:Part

a MIME part representing a signed message.

verifier:SignerInformationVerifier

the verifier we want to find a signer for.

Returns:boolean

true if cert verifies message, false otherwise.

Exceptions
SMIMEException:
on a SMIME handling issue.
MessagingException:
on a basic message processing exception
isValidSignatureback to summary
public boolean isValidSignature(MimeMultipart message, SignerInformationVerifier verifier) throws SMIMEException, MessagingException

Return true if there is a signature on the message that can be verified by verifier..

Parameters
message:MimeMultipart

a MIME part representing a signed message.

verifier:SignerInformationVerifier

the verifier we want to find a signer for.

Returns:boolean

true if cert verifies message, false otherwise.

Exceptions
SMIMEException:
on a SMIME handling issue.
MessagingException:
on a basic message processing exception
signback to summary
public MimeMultipart sign(MimeBodyPart message, 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:MimeBodyPart

the message to be signed.

signerInfoGenerator:SignerInfoGenerator

the generator to be used to generate the signature.

Returns:MimeMultipart

the resulting MimeMultipart

Exceptions
SMIMEException:
on an exception calculating or creating the signed data.
signEncapsulatedback to summary
public MimeBodyPart signEncapsulated(MimeBodyPart message, SignerInfoGenerator signerInfoGenerator) throws SMIMEException

Produce a signed message in encapsulated format where the message is encoded in the signature..

Parameters
message:MimeBodyPart

the message to be signed.

signerInfoGenerator:SignerInfoGenerator

the generator to be used to generate the signature.

Returns:MimeBodyPart

a BodyPart containing the encapsulated message.

Exceptions
SMIMEException:
on an exception calculating or creating the signed data.