Class SMIMESignedGenerator
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.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final Map
static final Map
static final Map
Fields inherited from class org.bouncycastle.mail.smime.SMIMEGenerator
encoding, useBase64
-
Constructor Summary
ConstructorDescriptionbase constructor - default content transfer encoding 7bitSMIMESignedGenerator
(String defaultContentTransferEncoding) base constructor - default content transfer encoding explicitly setSMIMESignedGenerator
(String defaultContentTransferEncoding, Map micAlgs) base constructor - default content transfer encoding explicitly setSMIMESignedGenerator
(Map micAlgs) base constructor - default content transfer encoding explicitly set -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAttributeCertificates
(org.bouncycastle.util.Store certStore) void
addCertificates
(org.bouncycastle.util.Store certStore) void
addCRLs
(org.bouncycastle.util.Store crlStore) void
addSignerInfoGenerator
(org.bouncycastle.cms.SignerInfoGenerator sigInfoGen) void
addSigners
(org.bouncycastle.cms.SignerInformationStore signerStore) Add a store of precalculated signers to the generator.javax.mail.internet.MimeMultipart
generate
(javax.mail.internet.MimeBodyPart content) javax.mail.internet.MimeMultipart
generate
(javax.mail.internet.MimeMessage message) javax.mail.internet.MimeBodyPart
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) generate a signed message with encapsulated contentjavax.mail.internet.MimeBodyPart
generateEncapsulated
(javax.mail.internet.MimeMessage message) Return a map of oids and byte arrays representing the digests calculated on the content during the last generate.Methods inherited from class org.bouncycastle.mail.smime.SMIMEGenerator
makeContentBodyPart, makeContentBodyPart, setContentTransferEncoding
-
Field Details
-
DIGEST_SHA1
-
DIGEST_MD5
-
DIGEST_SHA224
-
DIGEST_SHA256
-
DIGEST_SHA384
-
DIGEST_SHA512
-
DIGEST_GOST3411
-
DIGEST_RIPEMD128
-
DIGEST_RIPEMD160
-
DIGEST_RIPEMD256
-
ENCRYPTION_RSA
-
ENCRYPTION_DSA
-
ENCRYPTION_ECDSA
-
ENCRYPTION_RSA_PSS
-
ENCRYPTION_GOST3410
-
ENCRYPTION_ECGOST3410
-
ENCRYPTION_ECGOST3410_2012_256
-
ENCRYPTION_ECGOST3410_2012_512
-
RFC3851_MICALGS
-
RFC5751_MICALGS
-
STANDARD_MICALGS
-
-
Constructor Details
-
SMIMESignedGenerator
public SMIMESignedGenerator()base constructor - default content transfer encoding 7bit -
SMIMESignedGenerator
base constructor - default content transfer encoding explicitly set- Parameters:
defaultContentTransferEncoding
- new default to use.
-
SMIMESignedGenerator
base constructor - default content transfer encoding explicitly set- Parameters:
micAlgs
- a map of ANS1ObjectIdentifiers to strings hash algorithm names.
-
SMIMESignedGenerator
base constructor - default content transfer encoding explicitly set- Parameters:
defaultContentTransferEncoding
- new default to use.micAlgs
- a map of ANS1ObjectIdentifiers to strings hash algorithm names.
-
-
Method Details
-
addSigners
public void addSigners(org.bouncycastle.cms.SignerInformationStore signerStore) Add a store of precalculated signers to the generator.- Parameters:
signerStore
- store of signers
-
addSignerInfoGenerator
public void addSignerInfoGenerator(org.bouncycastle.cms.SignerInfoGenerator sigInfoGen) - Parameters:
sigInfoGen
-
-
addCertificates
public void addCertificates(org.bouncycastle.util.Store certStore) -
addCRLs
public void addCRLs(org.bouncycastle.util.Store crlStore) -
addAttributeCertificates
public void addAttributeCertificates(org.bouncycastle.util.Store certStore) -
getGeneratedDigests
Return a map of oids and byte arrays representing the digests calculated on the content during the last generate.- Returns:
- a map of oids (as String objects) and byte[] representing digests.
-
generate
public javax.mail.internet.MimeMultipart generate(javax.mail.internet.MimeBodyPart content) throws SMIMEException - Throws:
SMIMEException
-
generate
public javax.mail.internet.MimeMultipart generate(javax.mail.internet.MimeMessage message) throws SMIMEException - Throws:
SMIMEException
-
generateEncapsulated
public javax.mail.internet.MimeBodyPart generateEncapsulated(javax.mail.internet.MimeBodyPart content) throws SMIMEException generate a signed message with encapsulated contentNote: 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.
- Throws:
SMIMEException
-
generateEncapsulated
public javax.mail.internet.MimeBodyPart generateEncapsulated(javax.mail.internet.MimeMessage message) throws SMIMEException - Throws:
SMIMEException
-
generateCertificateManagement
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.
- Throws:
SMIMEException
-