certList.add(_signCert);
CertStore certs = CertStore.getInstance("Collection",
new CollectionCertStoreParameters(certList), "BC");
CMSSignedDataStreamGenerator gen = new CMSSignedDataStreamGenerator();
gen.addSigner(_origKP.getPrivate(), _origCert, CMSSignedDataStreamGenerator.DIGEST_SHA1, "BC");
gen.addCertificatesAndCRLs(certs);
OutputStream sigOut = gen.open(bOut, true);
sigOut.write(TEST_MESSAGE.getBytes());
sigOut.close();
CMSSignedDataParser sp = new CMSSignedDataParser(bOut.toByteArray());
sp.getSignedContent().drain();
verifySignatures(sp);
byte[] contentDigest = (byte[])gen.getGeneratedDigests().get(CMSSignedGenerator.DIGEST_SHA1);
AttributeTable table = ((SignerInformation)sp.getSignerInfos().getSigners().iterator().next()).getSignedAttributes();
Attribute hash = table.get(CMSAttributes.messageDigest);
assertTrue(MessageDigest.isEqual(contentDigest, ((ASN1OctetString)hash.getAttrValues().getObjectAt(0)).getOctets()));
//
// try using existing signer
//
gen = new CMSSignedDataStreamGenerator();
gen.addSigners(sp.getSignerInfos());
gen.addCertificatesAndCRLs(sp.getCertificatesAndCRLs("Collection", "BC"));
bOut.reset();
sigOut = gen.open(bOut, true);
sigOut.write(TEST_MESSAGE.getBytes());
sigOut.close();