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

public Class SMIMESignedGenerator

extends SMIMEGenerator
Class Inheritance
Imports
java.io.IOException, .OutputStream, java.security.AccessController, .PrivilegedAction, java.util.ArrayList, .Collections, .Enumeration, .HashMap, .Iterator, .List, .Map, .Set, .TreeSet, javax.activation.CommandMap, .MailcapCommandMap, javax.mail.MessagingException, .Multipart, javax.mail.internet.ContentType, .MimeBodyPart, .MimeMessage, .MimeMultipart, org.bouncycastle.asn1.ASN1ObjectIdentifier, org.bouncycastle.asn1.cryptopro.CryptoProObjectIdentifiers, org.bouncycastle.asn1.nist.NISTObjectIdentifiers, org.bouncycastle.asn1.oiw.OIWObjectIdentifiers, org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers, org.bouncycastle.asn1.teletrust.TeleTrusTObjectIdentifiers, org.bouncycastle.asn1.x9.X9ObjectIdentifiers, org.bouncycastle.cms.CMSAlgorithm, .CMSException, .CMSSignedDataStreamGenerator, .SignerInfoGenerator, .SignerInformation, .SignerInformationStore, org.bouncycastle.mail.smime.util.CRLFOutputStream, org.bouncycastle.util.Store

general class for generating a pkcs7-signature message.

A simple example of usage.

     X509Certificate signCert = ...
     KeyPair         signKP = ...

     List certList = new ArrayList();

     certList.add(signCert);

     Store certs = new JcaCertStore(certList);

     SMIMESignedGenerator gen = new SMIMESignedGenerator();

     gen.addSignerInfoGenerator(new JcaSimpleSignerInfoGeneratorBuilder().setProvider("BC").build("SHA1withRSA", signKP.getPrivate(), signCert));

     gen.addCertificates(certs);

     MimeMultipart       smime = fact.generate(content);

Note 1: 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".

Note 2: between RFC 3851 and RFC 5751 the values used in the micalg parameter for signed messages changed. We will accept both, but the default is now to use RFC 5751. In the event you are dealing with an older style system you will also need to use a constructor that sets the micalgs table and call it with RFC3851_MICALGS.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
private List<E>
private List<E>
private Map<K, V>
private List<E>
private List<E>
private List<E>
private static final String
private List<E>
private List<E>
private final String
private static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
private static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
private final Map<K, V>
public static final Map<K, V>
public static final Map<K, V>
private List<E>
public static final Map<K, V>
Inherited from org.bouncycastle.mail.smime.SMIMEGenerator:
encodinguseBase64

Constructor Summary

AccessConstructor and Description
public
SMIMESignedGenerator()

base constructor - default content transfer encoding 7bit

public
SMIMESignedGenerator(String
new default to use.
defaultContentTransferEncoding
)

base constructor - default content transfer encoding explicitly set

public
SMIMESignedGenerator(Map<K, V>
a map of ANS1ObjectIdentifiers to strings hash algorithm names.
micAlgs
)

base constructor - default content transfer encoding explicitly set

public
SMIMESignedGenerator(String
new default to use.
defaultContentTransferEncoding
,
Map<K, V>
a map of ANS1ObjectIdentifiers to strings hash algorithm names.
micAlgs
)

base constructor - default content transfer encoding explicitly set

Method Summary

Modifier and TypeMethod and Description
public void
public void
addCertificates(Store<T> certStore)

public void
addCRLs(Store<T> crlStore)

private void
addHashHeader(StringBuffer header, List<E> signers)

public void
public void
addSigners(SignerInformationStore
store of signers
signerStore
)

Add a store of precalculated signers to the generator.

public MimeMultipart
public MimeMultipart
public MimeBodyPart

Returns:

a MimeBodyPart containing the certs and CRLs.
generateCertificateManagement
()

Creates a certificate management message which is like a signed message with no content or signers but that still carries certificates and CRLs.

public MimeBodyPart
generateEncapsulated(MimeBodyPart content)

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.

public MimeBodyPart
public Map<K, V>

Returns:

a map of oids (as String objects) and byte[] representing digests.
getGeneratedDigests
()

Return a map of oids and byte arrays representing the digests calculated on the content during the last generate.

private MimeMultipart
make(MimeBodyPart content)

private MimeBodyPart
Inherited from org.bouncycastle.mail.smime.SMIMEGenerator:
createSymmetricKeyGeneratormakeContentBodyPartmakeContentBodyPartsetContentTransferEncoding

Field Detail

_attributeCertsback to summary
private List<E> _attributeCerts
_certStoresback to summary
private List<E> _certStores
_digestsback to summary
private Map<K, V> _digests
_oldSignersback to summary
private List<E> _oldSigners
_signersback to summary
private List<E> _signers
attrCertStoresback to summary
private List<E> attrCertStores
CERTIFICATE_MANAGEMENT_CONTENTback to summary
private static final String CERTIFICATE_MANAGEMENT_CONTENT
certStoresback to summary
private List<E> certStores
crlStoresback to summary
private List<E> crlStores
defaultContentTransferEncodingback to summary
private final String defaultContentTransferEncoding
DETACHED_SIGNATURE_TYPEback to summary
private static final String DETACHED_SIGNATURE_TYPE
DIGEST_GOST3411back to summary
public static final String DIGEST_GOST3411
DIGEST_MD5back to summary
public static final String DIGEST_MD5
DIGEST_RIPEMD128back to summary
public static final String DIGEST_RIPEMD128
DIGEST_RIPEMD160back to summary
public static final String DIGEST_RIPEMD160
DIGEST_RIPEMD256back to summary
public static final String DIGEST_RIPEMD256
DIGEST_SHA1back to summary
public static final String DIGEST_SHA1
DIGEST_SHA224back to summary
public static final String DIGEST_SHA224
DIGEST_SHA256back to summary
public static final String DIGEST_SHA256
DIGEST_SHA384back to summary
public static final String DIGEST_SHA384
DIGEST_SHA512back to summary
public static final String DIGEST_SHA512
ENCAPSULATED_SIGNED_CONTENT_TYPEback to summary
private static final String ENCAPSULATED_SIGNED_CONTENT_TYPE
ENCRYPTION_DSAback to summary
public static final String ENCRYPTION_DSA
ENCRYPTION_ECDSAback to summary
public static final String ENCRYPTION_ECDSA
ENCRYPTION_ECGOST3410back to summary
public static final String ENCRYPTION_ECGOST3410
ENCRYPTION_GOST3410back to summary
public static final String ENCRYPTION_GOST3410
ENCRYPTION_RSAback to summary
public static final String ENCRYPTION_RSA
ENCRYPTION_RSA_PSSback to summary
public static final String ENCRYPTION_RSA_PSS
micAlgsback to summary
private final Map<K, V> micAlgs
RFC3851_MICALGSback to summary
public static final Map<K, V> RFC3851_MICALGS
RFC5751_MICALGSback to summary
public static final Map<K, V> RFC5751_MICALGS
signerInfoGensback to summary
private List<E> signerInfoGens
STANDARD_MICALGSback to summary
public static final Map<K, V> STANDARD_MICALGS

Constructor Detail

SMIMESignedGeneratorback to summary
public SMIMESignedGenerator()

base constructor - default content transfer encoding 7bit

SMIMESignedGeneratorback to summary
public SMIMESignedGenerator(String defaultContentTransferEncoding)

base constructor - default content transfer encoding explicitly set

Parameters
defaultContentTransferEncoding:String

new default to use.

SMIMESignedGeneratorback to summary
public SMIMESignedGenerator(Map<K, V> micAlgs)

base constructor - default content transfer encoding explicitly set

Parameters
micAlgs:Map<K, V>

a map of ANS1ObjectIdentifiers to strings hash algorithm names.

SMIMESignedGeneratorback to summary
public SMIMESignedGenerator(String defaultContentTransferEncoding, Map<K, V> micAlgs)

base constructor - default content transfer encoding explicitly set

Parameters
defaultContentTransferEncoding:String

new default to use.

micAlgs:Map<K, V>

a map of ANS1ObjectIdentifiers to strings hash algorithm names.

Method Detail

addAttributeCertificatesback to summary
public void addAttributeCertificates(Store<T> certStore)
addCertificatesback to summary
public void addCertificates(Store<T> certStore)
addCRLsback to summary
public void addCRLs(Store<T> crlStore)
addHashHeaderback to summary
private void addHashHeader(StringBuffer header, List<E> signers)
addSignerInfoGeneratorback to summary
public void addSignerInfoGenerator(SignerInfoGenerator sigInfoGen)
addSignersback to summary
public void addSigners(SignerInformationStore signerStore)

Add a store of precalculated signers to the generator.

Parameters
signerStore:SignerInformationStore

store of signers

generateback to summary
public MimeMultipart generate(MimeBodyPart content) throws SMIMEException
generateback to summary
public MimeMultipart generate(MimeMessage message) throws SMIMEException
generateCertificateManagementback to summary
public MimeBodyPart generateCertificateManagement() throws SMIMEException

Creates a certificate management message which is like a signed message with no content or signers but that still carries certificates and CRLs.

Returns:MimeBodyPart

a MimeBodyPart containing the certs and CRLs.

generateEncapsulatedback to summary
public MimeBodyPart generateEncapsulated(MimeBodyPart content) throws 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.

generateEncapsulatedback to summary
public MimeBodyPart generateEncapsulated(MimeMessage message) throws SMIMEException
getGeneratedDigestsback to summary
public Map<K, V> getGeneratedDigests()

Return a map of oids and byte arrays representing the digests calculated on the content during the last generate.

Returns:Map<K, V>

a map of oids (as String objects) and byte[] representing digests.

makeback to summary
private MimeMultipart make(MimeBodyPart content) throws SMIMEException
makeEncapsulatedback to summary
private MimeBodyPart makeEncapsulated(MimeBodyPart content) throws SMIMEException
org.bouncycastle.mail.smime back to summary

private Class SMIMESignedGenerator.ContentSigner

extends Object
implements SMIMEStreamingProcessor
Class Inheritance
  • java.lang.Object
  • org.bouncycastle.mail.smime.SMIMESignedGenerator.ContentSigner
All Implemented Interfaces
org.bouncycastle.mail.smime.SMIMEStreamingProcessor

Field Summary

Modifier and TypeField and Description
private final MimeBodyPart
private final boolean
private final boolean

Constructor Summary

AccessConstructor and Description
pack-priv
ContentSigner(MimeBodyPart content, boolean encapsulate)

Method Summary

Modifier and TypeMethod and Description
protected CMSSignedDataStreamGenerator
public void
private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

contentback to summary
private final MimeBodyPart content
encapsulateback to summary
private final boolean encapsulate
noProviderback to summary
private final boolean noProvider

Constructor Detail

ContentSignerback to summary
pack-priv ContentSigner(MimeBodyPart content, boolean encapsulate)

Method Detail

getGeneratorback to summary
protected CMSSignedDataStreamGenerator getGenerator() throws CMSException
writeback to summary
public void write(OutputStream out) throws IOException

Implements org.bouncycastle.mail.smime.SMIMEStreamingProcessor.write.

writeBodyPartback to summary
private void writeBodyPart(OutputStream out, MimeBodyPart bodyPart) throws IOException, MessagingException