public class SMIMESignedGenerator extends SMIMEGenerator
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: 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".
Modifier and Type | Field and Description |
---|---|
static String |
DIGEST_GOST3411 |
static String |
DIGEST_MD5 |
static String |
DIGEST_RIPEMD128 |
static String |
DIGEST_RIPEMD160 |
static String |
DIGEST_RIPEMD256 |
static String |
DIGEST_SHA1 |
static String |
DIGEST_SHA224 |
static String |
DIGEST_SHA256 |
static String |
DIGEST_SHA384 |
static String |
DIGEST_SHA512 |
static String |
ENCRYPTION_DSA |
static String |
ENCRYPTION_ECDSA |
static String |
ENCRYPTION_ECGOST3410 |
static String |
ENCRYPTION_GOST3410 |
static String |
ENCRYPTION_RSA |
static String |
ENCRYPTION_RSA_PSS |
encoding, useBase64
Constructor and Description |
---|
SMIMESignedGenerator()
base constructor - default content transfer encoding 7bit
|
SMIMESignedGenerator(String defaultContentTransferEncoding)
base constructor - default content transfer encoding explicitly set
|
Modifier and Type | Method and Description |
---|---|
void |
addAttributeCertificates(Store certStore) |
void |
addAttributeCertificates(X509Store store)
Deprecated.
use addAttributeCertificates(Store)
|
void |
addCertificates(Store certStore) |
void |
addCertificatesAndCRLs(CertStore certStore)
Deprecated.
use addCertificates(Store) and addCRLs(Store)
|
void |
addCRLs(Store crlStore) |
void |
addSigner(PrivateKey key,
X509Certificate cert,
String digestOID)
Deprecated.
use addSignerInfoGenerator()
|
void |
addSigner(PrivateKey key,
X509Certificate cert,
String digestOID,
AttributeTable signedAttr,
AttributeTable unsignedAttr)
Deprecated.
use addSignerInfoGenerator()
|
void |
addSigner(PrivateKey key,
X509Certificate cert,
String encryptionOID,
String digestOID)
Deprecated.
use addSignerInfoGenerator()
|
void |
addSigner(PrivateKey key,
X509Certificate cert,
String encryptionOID,
String digestOID,
AttributeTable signedAttr,
AttributeTable unsignedAttr)
Deprecated.
use addSignerInfoGenerator()
|
void |
addSignerInfoGenerator(SignerInfoGenerator sigInfoGen) |
void |
addSigners(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.MimeBodyPart content,
Provider sigProvider)
generate a signed object that contains an SMIME Signed Multipart
object using the given provider.
|
javax.mail.internet.MimeMultipart |
generate(javax.mail.internet.MimeBodyPart content,
String sigProvider)
Deprecated.
use generate(MimeBodyPart)
|
javax.mail.internet.MimeMultipart |
generate(javax.mail.internet.MimeMessage message,
Provider sigProvider)
generate a signed object that contains an SMIME Signed Multipart
object using the given provider from the given MimeMessage
|
javax.mail.internet.MimeMultipart |
generate(javax.mail.internet.MimeMessage message,
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(Provider 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 |
generateCertificateManagement(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)
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.
|
javax.mail.internet.MimeBodyPart |
generateEncapsulated(javax.mail.internet.MimeBodyPart content,
Provider sigProvider)
Deprecated.
use generateEncapsulated(content)
|
javax.mail.internet.MimeBodyPart |
generateEncapsulated(javax.mail.internet.MimeBodyPart content,
String sigProvider)
Deprecated.
use generateEncapsulated(content)
|
javax.mail.internet.MimeBodyPart |
generateEncapsulated(javax.mail.internet.MimeMessage message,
Provider sigProvider)
Deprecated.
use generateEncapsulated(content)
|
javax.mail.internet.MimeBodyPart |
generateEncapsulated(javax.mail.internet.MimeMessage message,
String sigProvider)
Deprecated.
use generateEncapsulated(content)
|
Map |
getGeneratedDigests()
Return a map of oids and byte arrays representing the digests calculated on the content during
the last generate.
|
createSymmetricKeyGenerator, makeContentBodyPart, makeContentBodyPart, setContentTransferEncoding
public static final String DIGEST_SHA1
public static final String DIGEST_MD5
public static final String DIGEST_SHA224
public static final String DIGEST_SHA256
public static final String DIGEST_SHA384
public static final String DIGEST_SHA512
public static final String DIGEST_GOST3411
public static final String DIGEST_RIPEMD128
public static final String DIGEST_RIPEMD160
public static final String DIGEST_RIPEMD256
public static final String ENCRYPTION_RSA
public static final String ENCRYPTION_DSA
public static final String ENCRYPTION_ECDSA
public static final String ENCRYPTION_RSA_PSS
public static final String ENCRYPTION_GOST3410
public static final String ENCRYPTION_ECGOST3410
public SMIMESignedGenerator()
public SMIMESignedGenerator(String defaultContentTransferEncoding)
defaultContentTransferEncoding
- new default to use.public void addSigner(PrivateKey key, X509Certificate cert, String digestOID) throws IllegalArgumentException
key
- key to use to generate the signaturecert
- the public key certificate associated with the signer's key.digestOID
- object ID of the digest algorithm to use.IllegalArgumentException
- any of the arguments are inappropriatepublic void addSigner(PrivateKey key, X509Certificate cert, String encryptionOID, String digestOID) throws IllegalArgumentException
key
- key to use to generate the signaturecert
- the public key certificate associated with the signer's key.encryptionOID
- object ID of the digest ecnryption algorithm to use.digestOID
- object ID of the digest algorithm to use.IllegalArgumentException
- any of the arguments are inappropriatepublic void addSigner(PrivateKey key, X509Certificate cert, String digestOID, AttributeTable signedAttr, AttributeTable unsignedAttr) throws IllegalArgumentException
key
- key to use to generate the signaturecert
- the public key certificate associated with the signer's key.digestOID
- object ID of the digest algorithm to use.signedAttr
- signed attributes to be included in the signature.unsignedAttr
- unsigned attribitues to be included.IllegalArgumentException
- any of the arguments are inappropriatepublic void addSigner(PrivateKey key, X509Certificate cert, String encryptionOID, String digestOID, AttributeTable signedAttr, AttributeTable unsignedAttr) throws IllegalArgumentException
key
- key to use to generate the signaturecert
- the public key certificate associated with the signer's key.encryptionOID
- the digest encryption algorithm OID.digestOID
- object ID of the digest algorithm to use.signedAttr
- signed attributes to be included in the signature.unsignedAttr
- unsigned attribitues to be included.IllegalArgumentException
- any of the arguments are inappropriatepublic void addSigners(SignerInformationStore signerStore)
signerStore
- store of signerspublic void addSignerInfoGenerator(SignerInfoGenerator sigInfoGen)
public void addCertificatesAndCRLs(CertStore certStore) throws CertStoreException, SMIMEException
Note: this assumes the CertStore will support null in the get methods.
certStore
- CertStore containing the certificates and CRLs to be added.CertStoreException
SMIMEException
public void addCertificates(Store certStore)
public void addCRLs(Store crlStore)
public void addAttributeCertificates(Store certStore)
public void addAttributeCertificates(X509Store store) throws CMSException
store
- a store of Version 2 attribute certificatesCMSException
- if an error occurse processing the store.public Map getGeneratedDigests()
public javax.mail.internet.MimeMultipart generate(javax.mail.internet.MimeBodyPart content, String sigProvider) throws NoSuchAlgorithmException, NoSuchProviderException, SMIMEException
content
- the MimeBodyPart to be signed.sigProvider
- the provider to be used for the signature.NoSuchAlgorithmException
- if the required algorithms for the signature cannot be found.NoSuchProviderException
- if no provider can be found.SMIMEException
- if an exception occurs in processing the signature.public javax.mail.internet.MimeMultipart generate(javax.mail.internet.MimeBodyPart content, Provider sigProvider) throws NoSuchAlgorithmException, SMIMEException
content
- the MimeBodyPart to be signed.sigProvider
- the provider to be used for the signature.NoSuchAlgorithmException
- if the required algorithms for the signature cannot be found.SMIMEException
- if an exception occurs in processing the signature.public javax.mail.internet.MimeMultipart generate(javax.mail.internet.MimeMessage message, String sigProvider) throws NoSuchAlgorithmException, NoSuchProviderException, SMIMEException
NoSuchAlgorithmException
- if the required algorithms for the signature cannot be found.NoSuchProviderException
- if no provider can be found.SMIMEException
- if an exception occurs in processing the signature.public javax.mail.internet.MimeMultipart generate(javax.mail.internet.MimeMessage message, Provider sigProvider) throws NoSuchAlgorithmException, SMIMEException
NoSuchAlgorithmException
- if the required algorithms for the signature cannot be found.NoSuchProviderException
- if no provider can be found.SMIMEException
- if an exception occurs in processing the signature.public javax.mail.internet.MimeMultipart generate(javax.mail.internet.MimeBodyPart content) throws SMIMEException
SMIMEException
public javax.mail.internet.MimeBodyPart generateEncapsulated(javax.mail.internet.MimeBodyPart content) throws SMIMEException
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.
SMIMEException
public javax.mail.internet.MimeBodyPart generateEncapsulated(javax.mail.internet.MimeBodyPart content, String sigProvider) throws NoSuchAlgorithmException, NoSuchProviderException, SMIMEException
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 javax.mail.internet.MimeBodyPart generateEncapsulated(javax.mail.internet.MimeBodyPart content, Provider sigProvider) throws NoSuchAlgorithmException, NoSuchProviderException, SMIMEException
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 javax.mail.internet.MimeBodyPart generateEncapsulated(javax.mail.internet.MimeMessage message, String sigProvider) throws NoSuchAlgorithmException, NoSuchProviderException, SMIMEException
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 javax.mail.internet.MimeBodyPart generateEncapsulated(javax.mail.internet.MimeMessage message, Provider sigProvider) throws NoSuchAlgorithmException, SMIMEException
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 javax.mail.internet.MimeBodyPart generateCertificateManagement(String provider) throws SMIMEException, NoSuchProviderException
SMIMEException
NoSuchProviderException
public javax.mail.internet.MimeBodyPart generateCertificateManagement(Provider provider) throws SMIMEException
SMIMEException
Copyright © 2015. All rights reserved.