// Add our signer info and sign the message
if ((serviceReq.getMode() & CmsCAServiceRequest.MODE_SIGN) != 0) {
final CertStore certs = CertStore.getInstance("Collection", new CollectionCertStoreParameters(certificatechain), "BC");
gen1.addCertificatesAndCRLs(certs);
gen1.addSigner(privKey, signerCert, CMSSignedGenerator.DIGEST_SHA1);
final CMSProcessable msg = new CMSProcessableByteArray(resp);
final CMSSignedData s = gen1.generate(msg, true, "BC");
resp = s.getEncoded();
}
if ((serviceReq.getMode() & CmsCAServiceRequest.MODE_ENCRYPT) != 0) {
CMSEnvelopedDataGenerator edGen = new CMSEnvelopedDataGenerator();
edGen.addKeyTransRecipient(getCMSCertificate());
CMSEnvelopedData ed = edGen.generate(new CMSProcessableByteArray(resp),CMSEnvelopedDataGenerator.DES_EDE3_CBC,"BC");
resp = ed.getEncoded();
}
if ((serviceReq.getMode() & CmsCAServiceRequest.MODE_DECRYPT) != 0) {
CMSEnvelopedData ed = new CMSEnvelopedData(resp);
RecipientInformationStore recipients = ed.getRecipientInfos();