Package org.bouncycastle.cms
Class CMSSignedDataGenerator
java.lang.Object
org.bouncycastle.cms.CMSSignedGenerator
org.bouncycastle.cms.CMSSignedDataGenerator
public class CMSSignedDataGenerator extends CMSSignedGenerator
general class for generating a pkcs7-signature message.
A simple example of usage, generating a detached signature.
List certList = new ArrayList();
CMSTypedData msg = new CMSProcessableByteArray("Hello world!".getBytes());
certList.add(signCert);
Store certs = new JcaCertStore(certList);
CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
ContentSigner sha1Signer = new JcaContentSignerBuilder("SHA1withRSA").setProvider("BC").build(signKP.getPrivate());
gen.addSignerInfoGenerator(
new JcaSignerInfoGeneratorBuilder(
new JcaDigestCalculatorProviderBuilder().setProvider("BC").build())
.build(sha1Signer, signCert));
gen.addCertificates(certs);
CMSSignedData sigData = gen.generate(msg, false);
-
Field Summary
Fields inherited from class org.bouncycastle.cms.CMSSignedGenerator
_signers, certs, crls, DATA, DIGEST_MD5, DIGEST_SHA1, DIGEST_SHA256, DIGEST_SHA384, DIGEST_SHA512, digests, ENCRYPTION_DSA, ENCRYPTION_ECDSA, ENCRYPTION_RSA, ENCRYPTION_RSA_PSS, rand, signerGens -
Constructor Summary
Constructors Constructor Description CMSSignedDataGenerator()base constructorCMSSignedDataGenerator(SecureRandom rand)Deprecated.rand ignored in new API, use base constructor. -
Method Summary
Modifier and Type Method Description voidaddSigner(PrivateKey key, byte[] subjectKeyID, String digestOID)Deprecated.use addSignerInfoGeneratorvoidaddSigner(PrivateKey key, byte[] subjectKeyID, String encryptionOID, String digestOID)Deprecated.use addSignerInfoGeneratorvoidaddSigner(PrivateKey key, byte[] subjectKeyID, String encryptionOID, String digestOID, AttributeTable signedAttr, AttributeTable unsignedAttr)Deprecated.use addSignerInfoGeneratorvoidaddSigner(PrivateKey key, byte[] subjectKeyID, String encryptionOID, String digestOID, CMSAttributeTableGenerator signedAttrGen, CMSAttributeTableGenerator unsignedAttrGen)Deprecated.use addSignerInfoGeneratorvoidaddSigner(PrivateKey key, byte[] subjectKeyID, String digestOID, AttributeTable signedAttr, AttributeTable unsignedAttr)Deprecated.use addSignerInfoGeneratorvoidaddSigner(PrivateKey key, byte[] subjectKeyID, String digestOID, CMSAttributeTableGenerator signedAttrGen, CMSAttributeTableGenerator unsignedAttrGen)Deprecated.use addSignerInfoGeneratorvoidaddSigner(PrivateKey key, X509Certificate cert, String digestOID)Deprecated.use addSignerInfoGeneratorvoidaddSigner(PrivateKey key, X509Certificate cert, String encryptionOID, String digestOID)Deprecated.use addSignerInfoGeneratorvoidaddSigner(PrivateKey key, X509Certificate cert, String encryptionOID, String digestOID, AttributeTable signedAttr, AttributeTable unsignedAttr)Deprecated.use addSignerInfoGeneratorvoidaddSigner(PrivateKey key, X509Certificate cert, String encryptionOID, String digestOID, CMSAttributeTableGenerator signedAttrGen, CMSAttributeTableGenerator unsignedAttrGen)Deprecated.use addSignerInfoGeneratorvoidaddSigner(PrivateKey key, X509Certificate cert, String digestOID, AttributeTable signedAttr, AttributeTable unsignedAttr)Deprecated.use addSignerInfoGeneratorvoidaddSigner(PrivateKey key, X509Certificate cert, String digestOID, CMSAttributeTableGenerator signedAttrGen, CMSAttributeTableGenerator unsignedAttrGen)Deprecated.use addSignerInfoGeneratorCMSSignedDatagenerate(String eContentType, CMSProcessable content, boolean encapsulate, String sigProvider)Deprecated.use generate(CMSTypedData, boolean)CMSSignedDatagenerate(String eContentType, CMSProcessable content, boolean encapsulate, String sigProvider, boolean addDefaultAttributes)Deprecated.use generate(CMSTypedData, boolean)CMSSignedDatagenerate(String eContentType, CMSProcessable content, boolean encapsulate, Provider sigProvider)Deprecated.use generate(CMSTypedData, boolean)CMSSignedDatagenerate(String eContentType, CMSProcessable content, boolean encapsulate, Provider sigProvider, boolean addDefaultAttributes)Deprecated.use setDirectSignature() on SignerInformationGenerator.CMSSignedDatagenerate(CMSProcessable content, boolean encapsulate, String sigProvider)Deprecated.use generate(CMSTypedData, boolean)CMSSignedDatagenerate(CMSProcessable content, boolean encapsulate, Provider sigProvider)Deprecated.use generate(CMSTypedData, boolean)CMSSignedDatagenerate(CMSProcessable content, String sigProvider)Deprecated.use generate() method not taking provider.CMSSignedDatagenerate(CMSProcessable content, Provider sigProvider)Deprecated.use generate() method not taking provider.CMSSignedDatagenerate(CMSTypedData content)CMSSignedDatagenerate(CMSTypedData content, boolean encapsulate)SignerInformationStoregenerateCounterSigners(SignerInformation signer)generate a set of one or more SignerInformation objects representing counter signatures on the passed in SignerInformation object.SignerInformationStoregenerateCounterSigners(SignerInformation signer, String sigProvider)Deprecated.use generateCounterSigners(SignerInformation)SignerInformationStoregenerateCounterSigners(SignerInformation signer, Provider sigProvider)Deprecated.use generateCounterSigners(SignerInformation)Methods inherited from class org.bouncycastle.cms.CMSSignedGenerator
addAttributeCertificate, addAttributeCertificates, addAttributeCertificates, addCertificate, addCertificates, addCertificatesAndCRLs, addCRL, addCRLs, addSignerInfoGenerator, addSigners, getAttributeSet, getBaseParameters, getEncOID, getGeneratedDigests
-
Constructor Details
-
CMSSignedDataGenerator
public CMSSignedDataGenerator()base constructor -
CMSSignedDataGenerator
Deprecated.rand ignored in new API, use base constructor.constructor allowing specific source of randomness- Parameters:
rand- instance of SecureRandom to use
-
-
Method Details
-
addSigner
public void addSigner(PrivateKey key, X509Certificate cert, String digestOID) throws IllegalArgumentExceptionDeprecated.use addSignerInfoGeneratoradd a signer - no attributes other than the default ones will be provided here.- Parameters:
key- signing key to usecert- certificate containing corresponding public keydigestOID- digest algorithm OID- Throws:
IllegalArgumentException
-
addSigner
public void addSigner(PrivateKey key, X509Certificate cert, String encryptionOID, String digestOID) throws IllegalArgumentExceptionDeprecated.use addSignerInfoGeneratoradd a signer, specifying the digest encryption algorithm to use - no attributes other than the default ones will be provided here.- Parameters:
key- signing key to usecert- certificate containing corresponding public keyencryptionOID- digest encryption algorithm OIDdigestOID- digest algorithm OID- Throws:
IllegalArgumentException
-
addSigner
public void addSigner(PrivateKey key, byte[] subjectKeyID, String digestOID) throws IllegalArgumentExceptionDeprecated.use addSignerInfoGeneratoradd a signer - no attributes other than the default ones will be provided here.- Throws:
IllegalArgumentException
-
addSigner
public void addSigner(PrivateKey key, byte[] subjectKeyID, String encryptionOID, String digestOID) throws IllegalArgumentExceptionDeprecated.use addSignerInfoGeneratoradd a signer, specifying the digest encryption algorithm to use - no attributes other than the default ones will be provided here.- Throws:
IllegalArgumentException
-
addSigner
public void addSigner(PrivateKey key, X509Certificate cert, String digestOID, AttributeTable signedAttr, AttributeTable unsignedAttr) throws IllegalArgumentExceptionDeprecated.use addSignerInfoGeneratoradd a signer with extra signed/unsigned attributes.- Parameters:
key- signing key to usecert- certificate containing corresponding public keydigestOID- digest algorithm OIDsignedAttr- table of attributes to be included in signatureunsignedAttr- table of attributes to be included as unsigned- Throws:
IllegalArgumentException
-
addSigner
public void addSigner(PrivateKey key, X509Certificate cert, String encryptionOID, String digestOID, AttributeTable signedAttr, AttributeTable unsignedAttr) throws IllegalArgumentExceptionDeprecated.use addSignerInfoGeneratoradd a signer, specifying the digest encryption algorithm, with extra signed/unsigned attributes.- Parameters:
key- signing key to usecert- certificate containing corresponding public keyencryptionOID- digest encryption algorithm OIDdigestOID- digest algorithm OIDsignedAttr- table of attributes to be included in signatureunsignedAttr- table of attributes to be included as unsigned- Throws:
IllegalArgumentException
-
addSigner
public void addSigner(PrivateKey key, byte[] subjectKeyID, String digestOID, AttributeTable signedAttr, AttributeTable unsignedAttr) throws IllegalArgumentExceptionDeprecated.use addSignerInfoGeneratoradd a signer with extra signed/unsigned attributes.- Parameters:
key- signing key to usesubjectKeyID- subjectKeyID of corresponding public keydigestOID- digest algorithm OIDsignedAttr- table of attributes to be included in signatureunsignedAttr- table of attributes to be included as unsigned- Throws:
IllegalArgumentException
-
addSigner
public void addSigner(PrivateKey key, byte[] subjectKeyID, String encryptionOID, String digestOID, AttributeTable signedAttr, AttributeTable unsignedAttr) throws IllegalArgumentExceptionDeprecated.use addSignerInfoGeneratoradd a signer, specifying the digest encryption algorithm, with extra signed/unsigned attributes.- Parameters:
key- signing key to usesubjectKeyID- subjectKeyID of corresponding public keyencryptionOID- digest encryption algorithm OIDdigestOID- digest algorithm OIDsignedAttr- table of attributes to be included in signatureunsignedAttr- table of attributes to be included as unsigned- Throws:
IllegalArgumentException
-
addSigner
public void addSigner(PrivateKey key, X509Certificate cert, String digestOID, CMSAttributeTableGenerator signedAttrGen, CMSAttributeTableGenerator unsignedAttrGen) throws IllegalArgumentExceptionDeprecated.use addSignerInfoGeneratoradd a signer with extra signed/unsigned attributes based on generators.- Throws:
IllegalArgumentException
-
addSigner
public void addSigner(PrivateKey key, X509Certificate cert, String encryptionOID, String digestOID, CMSAttributeTableGenerator signedAttrGen, CMSAttributeTableGenerator unsignedAttrGen) throws IllegalArgumentExceptionDeprecated.use addSignerInfoGeneratoradd a signer, specifying the digest encryption algorithm, with extra signed/unsigned attributes based on generators.- Throws:
IllegalArgumentException
-
addSigner
public void addSigner(PrivateKey key, byte[] subjectKeyID, String digestOID, CMSAttributeTableGenerator signedAttrGen, CMSAttributeTableGenerator unsignedAttrGen) throws IllegalArgumentExceptionDeprecated.use addSignerInfoGeneratoradd a signer with extra signed/unsigned attributes based on generators.- Throws:
IllegalArgumentException
-
addSigner
public void addSigner(PrivateKey key, byte[] subjectKeyID, String encryptionOID, String digestOID, CMSAttributeTableGenerator signedAttrGen, CMSAttributeTableGenerator unsignedAttrGen) throws IllegalArgumentExceptionDeprecated.use addSignerInfoGeneratoradd a signer, including digest encryption algorithm, with extra signed/unsigned attributes based on generators.- Throws:
IllegalArgumentException
-
generate
public CMSSignedData generate(CMSProcessable content, String sigProvider) throws NoSuchAlgorithmException, NoSuchProviderException, CMSExceptionDeprecated.use generate() method not taking provider.generate a signed object that for a CMS Signed Data object using the given provider. -
generate
public CMSSignedData generate(CMSProcessable content, Provider sigProvider) throws NoSuchAlgorithmException, CMSExceptionDeprecated.use generate() method not taking provider.generate a signed object that for a CMS Signed Data object using the given provider.- Throws:
NoSuchAlgorithmExceptionCMSException
-
generate
public CMSSignedData generate(String eContentType, CMSProcessable content, boolean encapsulate, String sigProvider) throws NoSuchAlgorithmException, NoSuchProviderException, CMSExceptionDeprecated.use generate(CMSTypedData, boolean)generate a signed object that for a CMS Signed Data object using the given provider - if encapsulate is true a copy of the message will be included in the signature. The content type is set according to the OID represented by the string signedContentType. -
generate
public CMSSignedData generate(String eContentType, CMSProcessable content, boolean encapsulate, Provider sigProvider) throws NoSuchAlgorithmException, CMSExceptionDeprecated.use generate(CMSTypedData, boolean)generate a signed object that for a CMS Signed Data object using the given provider - if encapsulate is true a copy of the message will be included in the signature. The content type is set according to the OID represented by the string signedContentType.- Throws:
NoSuchAlgorithmExceptionCMSException
-
generate
public CMSSignedData generate(String eContentType, CMSProcessable content, boolean encapsulate, String sigProvider, boolean addDefaultAttributes) throws NoSuchAlgorithmException, NoSuchProviderException, CMSExceptionDeprecated.use generate(CMSTypedData, boolean)Similar method to the other generate methods. The additional argument addDefaultAttributes indicates whether or not a default set of signed attributes need to be added automatically. If the argument is set to false, no attributes will get added at all. -
generate
public CMSSignedData generate(String eContentType, CMSProcessable content, boolean encapsulate, Provider sigProvider, boolean addDefaultAttributes) throws NoSuchAlgorithmException, CMSExceptionDeprecated.use setDirectSignature() on SignerInformationGenerator.Similar method to the other generate methods. The additional argument addDefaultAttributes indicates whether or not a default set of signed attributes need to be added automatically. If the argument is set to false, no attributes will get added at all.- Throws:
NoSuchAlgorithmExceptionCMSException
-
generate
public CMSSignedData generate(CMSProcessable content, boolean encapsulate, String sigProvider) throws NoSuchAlgorithmException, NoSuchProviderException, CMSExceptionDeprecated.use generate(CMSTypedData, boolean)generate a signed object that for a CMS Signed Data object using the given provider - if encapsulate is true a copy of the message will be included in the signature with the default content type "data". -
generate
public CMSSignedData generate(CMSProcessable content, boolean encapsulate, Provider sigProvider) throws NoSuchAlgorithmException, CMSExceptionDeprecated.use generate(CMSTypedData, boolean)generate a signed object that for a CMS Signed Data object using the given provider - if encapsulate is true a copy of the message will be included in the signature with the default content type "data".- Throws:
NoSuchAlgorithmExceptionCMSException
-
generate
- Throws:
CMSException
-
generate
- Throws:
CMSException
-
generateCounterSigners
public SignerInformationStore generateCounterSigners(SignerInformation signer, Provider sigProvider) throws NoSuchAlgorithmException, CMSExceptionDeprecated.use generateCounterSigners(SignerInformation)generate a set of one or more SignerInformation objects representing counter signatures on the passed in SignerInformation object.- Parameters:
signer- the signer to be countersignedsigProvider- the provider to be used for counter signing.- Returns:
- a store containing the signers.
- Throws:
NoSuchAlgorithmExceptionCMSException
-
generateCounterSigners
public SignerInformationStore generateCounterSigners(SignerInformation signer, String sigProvider) throws NoSuchAlgorithmException, NoSuchProviderException, CMSExceptionDeprecated.use generateCounterSigners(SignerInformation)generate a set of one or more SignerInformation objects representing counter signatures on the passed in SignerInformation object.- Parameters:
signer- the signer to be countersignedsigProvider- the provider to be used for counter signing.- Returns:
- a store containing the signers.
- Throws:
NoSuchAlgorithmExceptionNoSuchProviderExceptionCMSException
-
generateCounterSigners
generate a set of one or more SignerInformation objects representing counter signatures on the passed in SignerInformation object.- Parameters:
signer- the signer to be countersigned- Returns:
- a store containing the signers.
- Throws:
CMSException
-