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

public Class SMIMESigned

extends CMSSignedData
Class Inheritance
Imports
java.io.ByteArrayInputStream, .ByteArrayOutputStream, .IOException, .InputStream, java.security.AccessController, .PrivilegedAction, jakarta.activation.CommandMap, .MailcapCommandMap, jakarta.mail.MessagingException, .Part, .Session, jakarta.mail.internet.MimeBodyPart, .MimeMessage, .MimeMultipart, .MimePart, org.bouncycastle.cms.CMSException, .CMSProcessable, .CMSSignedData

general class for handling a pkcs7-signature message.

A simple example of usage - note, in the example below the validity of the certificate isn't verified, just the fact that one of the certs matches the given signer...

 CertStore               certs = s.getCertificates("Collection", "BC");
 SignerInformationStore  signers = s.getSignerInfos();
 Collection              c = signers.getSigners();
 Iterator                it = c.iterator();

 while (it.hasNext())
 {
     SignerInformation   signer = (SignerInformation)it.next();
     Collection          certCollection = certs.getCertificates(signer.getSID());

     Iterator        certIt = certCollection.iterator();
     X509Certificate cert = (X509Certificate)certIt.next();

     if (signer.verify(cert.getPublicKey()))
     {
         verified++;
     }   
 }

Note

if you are using this class with AS2 or some other protocol that does not use 7bit as the default content transfer encoding you will need to use the constructor that allows you to specify the default content transfer encoding, such as "binary".

Field Summary

Modifier and TypeField and Description
pack-priv MimeBodyPart
pack-priv Object

Constructor Summary

AccessConstructor and Description
public
SMIMESigned(MimeMultipart message)

base constructor using a defaultContentTransferEncoding of 7bit

public
SMIMESigned(MimeMultipart
the signed message
message
,
String
new default to use
defaultContentTransferEncoding
)

base constructor with settable contentTransferEncoding

public
SMIMESigned(Part message)

base constructor for a signed message with encapsulated content.

Method Summary

Modifier and TypeMethod and Description
public MimeBodyPart
getContent()

return the content that was signed.

public MimeMessage

Returns:

a MimeMessage holding the content.
getContentAsMimeMessage
(Session session)

Return the content that was signed as a mime message.

public Object
getContentWithSignature()

return the content that was signed - depending on whether this was unencapsulated or not it will return a MimeMultipart or a MimeBodyPart

private static InputStream
getInputStream(Part bodyPart)

Inherited from org.bouncycastle.cms.CMSSignedData:
addDigestAlgorithmgetAttributeCertificatesgetCertificatesgetCRLsgetDigestAlgorithmIDsgetEncodedgetEncodedgetOtherRevocationInfogetSignedContentgetSignedContentTypeOIDgetSignerInfosgetVersionisCertificateManagementMessageisDetachedSignaturereplaceCertificatesAndCRLsreplaceSignerstoASN1StructureverifySignaturesverifySignatures

Field Detail

contentback to summary
pack-priv MimeBodyPart content
messageback to summary
pack-priv Object message

Constructor Detail

SMIMESignedback to summary
public SMIMESigned(MimeMultipart message) throws MessagingException, CMSException

base constructor using a defaultContentTransferEncoding of 7bit

Exceptions
MessagingException:
on an error extracting the signature or otherwise processing the message.
CMSException:
if some other problem occurs.
SMIMESignedback to summary
public SMIMESigned(MimeMultipart message, String defaultContentTransferEncoding) throws MessagingException, CMSException

base constructor with settable contentTransferEncoding

Parameters
message:MimeMultipart

the signed message

defaultContentTransferEncoding:String

new default to use

Exceptions
MessagingException:
on an error extracting the signature or otherwise processing the message.
CMSException:
if some other problem occurs.
SMIMESignedback to summary
public SMIMESigned(Part message) throws MessagingException, CMSException, SMIMEException

base constructor for a signed message with encapsulated content.

Exceptions
MessagingException:
on an error extracting the signature or otherwise processing the message.
CMSException:
if some other problem occurs.
SMIMEException:
if the body part encapsulated in the message cannot be extracted.

Method Detail

getContentback to summary
public MimeBodyPart getContent()

return the content that was signed.

getContentAsMimeMessageback to summary
public MimeMessage getContentAsMimeMessage(Session session) throws MessagingException, IOException

Return the content that was signed as a mime message.

Returns:MimeMessage

a MimeMessage holding the content.

getContentWithSignatureback to summary
public Object getContentWithSignature()

return the content that was signed - depending on whether this was unencapsulated or not it will return a MimeMultipart or a MimeBodyPart

getInputStreamback to summary
private static InputStream getInputStream(Part bodyPart) throws MessagingException