gen.addSigner(_origKP.getPrivate(), _origCert, CMSSignedDataGenerator.DIGEST_SHA1);
gen.addCertificatesAndCRLs(certs);
CMSSignedData original = gen.generate(msg, true, "BC");
//
// create new Signer
//
gen = new CMSSignedDataGenerator();
gen.addSigner(_origKP.getPrivate(), _origCert, CMSSignedDataGenerator.DIGEST_SHA224);
gen.addCertificatesAndCRLs(certs);
CMSSignedData newSD = gen.generate(msg, true, "BC");
//
// replace signer
//
CMSSignedData sd = CMSSignedData.replaceSigners(original, newSD.getSignerInfos());
SignerInformation signer = (SignerInformation)sd.getSignerInfos().getSigners().iterator().next();
assertEquals(CMSSignedDataGenerator.DIGEST_SHA224, signer.getDigestAlgOID());
// we use a parser here as it requires the digests to be correct in the digest set, if it
// isn't we'll get a NullPointerException
CMSSignedDataParser sp = new CMSSignedDataParser(sd.getEncoded());
sp.getSignedContent().drain();
verifySignatures(sp);
}