Bouncy Castle Cryptography 1.30

org.bouncycastle.mail.smime
Class SMIMESignedGenerator

java.lang.Object
  |
  +--org.bouncycastle.mail.smime.SMIMEGenerator
        |
        +--org.bouncycastle.mail.smime.SMIMESignedGenerator

public class SMIMESignedGenerator
extends SMIMEGenerator

general class for generating a pkcs7-signature message.

A simple example of usage.

      CertStore           certs...
      SMIMESignedGenerator  fact = new SMIMESignedGenerator();

      fact.addSigner(privKey, cert, SMIMESignedGenerator.DIGEST_SHA1);
      fact.addCertificatesAndCRLs(certs);

      MimeMultipart       smime = fact.generate(content, "BC");
 

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
static java.lang.String DIGEST_MD5
           
static java.lang.String DIGEST_SHA1
           
static java.lang.String DIGEST_SHA224
           
static java.lang.String DIGEST_SHA256
           
static java.lang.String DIGEST_SHA384
           
static java.lang.String DIGEST_SHA512
           
static java.lang.String ENCRYPTION_DSA
           
static java.lang.String ENCRYPTION_RSA
           
 
Fields inherited from class org.bouncycastle.mail.smime.SMIMEGenerator
encoding, useBase64
 
Constructor Summary
SMIMESignedGenerator()
          base constructor - default content transfer encoding 7bit
SMIMESignedGenerator(java.lang.String defaultContentTransferEncoding)
          base constructor - default content transfer encoding explicitly set
 
Method Summary
 void addCertificatesAndCRLs(org.bouncycastle.jce.cert.CertStore certStore)
          add the certificates and CRLs contained in the given CertStore to the pool that will be included in the encoded signature block.
 void addSigner(java.security.PrivateKey key, java.security.cert.X509Certificate cert, java.lang.String digestOID)
          add a signer - no attributes other than the default ones will be provided here.
 void addSigner(java.security.PrivateKey key, java.security.cert.X509Certificate cert, java.lang.String digestOID, org.bouncycastle.asn1.cms.AttributeTable signedAttr, org.bouncycastle.asn1.cms.AttributeTable unsignedAttr)
          add a signer with extra signed/unsigned attributes.
 javax.mail.internet.MimeMultipart generate(javax.mail.internet.MimeBodyPart content, java.lang.String sigProvider)
          generate a signed object that contains an SMIME Signed Multipart object using the given provider.
 javax.mail.internet.MimeMultipart generate(javax.mail.internet.MimeMessage message, java.lang.String sigProvider)
          generate a signed object that contains an SMIME Signed Multipart object using the given provider from the given MimeMessage
 javax.mail.internet.MimeBodyPart generateCertificateManagement(java.lang.String provider)
          Creates a certificate management message which is like a signed message with no content or signers but that still carries certificates and CRLs.
 javax.mail.internet.MimeBodyPart generateEncapsulated(javax.mail.internet.MimeBodyPart content, java.lang.String sigProvider)
          generate a signed message with encapsulated content
 javax.mail.internet.MimeBodyPart generateEncapsulated(javax.mail.internet.MimeMessage message, java.lang.String sigProvider)
          generate a signed object that contains an SMIME Signed Multipart object using the given provider from the given MimeMessage.
 
Methods inherited from class org.bouncycastle.mail.smime.SMIMEGenerator
makeContentBodyPart, makeContentBodyPart, setContentTransferEncoding
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DIGEST_SHA1

public static final java.lang.String DIGEST_SHA1

DIGEST_MD5

public static final java.lang.String DIGEST_MD5

DIGEST_SHA224

public static final java.lang.String DIGEST_SHA224

DIGEST_SHA256

public static final java.lang.String DIGEST_SHA256

DIGEST_SHA384

public static final java.lang.String DIGEST_SHA384

DIGEST_SHA512

public static final java.lang.String DIGEST_SHA512

ENCRYPTION_RSA

public static final java.lang.String ENCRYPTION_RSA

ENCRYPTION_DSA

public static final java.lang.String ENCRYPTION_DSA
Constructor Detail

SMIMESignedGenerator

public SMIMESignedGenerator()
base constructor - default content transfer encoding 7bit

SMIMESignedGenerator

public SMIMESignedGenerator(java.lang.String defaultContentTransferEncoding)
base constructor - default content transfer encoding explicitly set
Parameters:
defaultContentTransferEncoding - new default to use.
Method Detail

addSigner

public void addSigner(java.security.PrivateKey key,
                      java.security.cert.X509Certificate cert,
                      java.lang.String digestOID)
               throws java.lang.IllegalArgumentException
add a signer - no attributes other than the default ones will be provided here.

addSigner

public void addSigner(java.security.PrivateKey key,
                      java.security.cert.X509Certificate cert,
                      java.lang.String digestOID,
                      org.bouncycastle.asn1.cms.AttributeTable signedAttr,
                      org.bouncycastle.asn1.cms.AttributeTable unsignedAttr)
               throws java.lang.IllegalArgumentException
add a signer with extra signed/unsigned attributes.

addCertificatesAndCRLs

public void addCertificatesAndCRLs(org.bouncycastle.jce.cert.CertStore certStore)
                            throws org.bouncycastle.jce.cert.CertStoreException,
                                   SMIMEException
add the certificates and CRLs contained in the given CertStore to the pool that will be included in the encoded signature block.

Note: this assumes the CertStore will support null in the get methods.


generate

public javax.mail.internet.MimeMultipart generate(javax.mail.internet.MimeBodyPart content,
                                                  java.lang.String sigProvider)
                                           throws java.security.NoSuchAlgorithmException,
                                                  java.security.NoSuchProviderException,
                                                  SMIMEException
generate a signed object that contains an SMIME Signed Multipart object using the given provider.

generate

public javax.mail.internet.MimeMultipart generate(javax.mail.internet.MimeMessage message,
                                                  java.lang.String sigProvider)
                                           throws java.security.NoSuchAlgorithmException,
                                                  java.security.NoSuchProviderException,
                                                  SMIMEException
generate a signed object that contains an SMIME Signed Multipart object using the given provider from the given MimeMessage

generateEncapsulated

public javax.mail.internet.MimeBodyPart generateEncapsulated(javax.mail.internet.MimeBodyPart content,
                                                             java.lang.String sigProvider)
                                                      throws java.security.NoSuchAlgorithmException,
                                                             java.security.NoSuchProviderException,
                                                             SMIMEException
generate a signed message with encapsulated content

Note: doing this is strongly not recommended as it means a recipient of the message will have to be able to read the signature to read the message.


generateEncapsulated

public javax.mail.internet.MimeBodyPart generateEncapsulated(javax.mail.internet.MimeMessage message,
                                                             java.lang.String sigProvider)
                                                      throws java.security.NoSuchAlgorithmException,
                                                             java.security.NoSuchProviderException,
                                                             SMIMEException
generate a signed object that contains an SMIME Signed Multipart object using the given provider from the given MimeMessage.

Note: doing this is strongly not recommended as it means a recipient of the message will have to be able to read the signature to read the message.


generateCertificateManagement

public javax.mail.internet.MimeBodyPart generateCertificateManagement(java.lang.String provider)
                                                               throws SMIMEException,
                                                                      java.security.NoSuchProviderException
Creates a certificate management message which is like a signed message with no content or signers but that still carries certificates and CRLs.
Returns:
a MimeBodyPart containing the certs and CRLs.

Bouncy Castle Cryptography 1.30