certList.add(_signCert);
CertStore certs = CertStore.getInstance("Collection",
new CollectionCertStoreParameters(certList), "BC");
CMSSignedDataStreamGenerator gen = new CMSSignedDataStreamGenerator();
CMSAttributeTableGenerator signedGen = new DefaultSignedAttributeTableGenerator()
{
public AttributeTable getAttributes(Map parameters)
{
Hashtable table = createStandardAttributeTable(parameters);
DEROctetString val = new DEROctetString((byte[])parameters.get(CMSAttributeTableGenerator.DIGEST));
Attribute attr = new Attribute(dummyOid1, new DERSet(val));
table.put(attr.getAttrType(), attr);
return new AttributeTable(table);
}
};
CMSAttributeTableGenerator unsignedGen = new CMSAttributeTableGenerator()
{
public AttributeTable getAttributes(Map parameters)
{
DEROctetString val = new DEROctetString((byte[])parameters.get(CMSAttributeTableGenerator.SIGNATURE));
Attribute attr = new Attribute(dummyOid2, new DERSet(val));
return new AttributeTable(new DERSet(attr));
}
};
gen.addSigner(_origKP.getPrivate(), _origCert, CMSSignedDataStreamGenerator.DIGEST_SHA1, signedGen, unsignedGen, "BC");
gen.addCertificatesAndCRLs(certs);
OutputStream sigOut = gen.open(bOut, true);
sigOut.write(TEST_MESSAGE.getBytes());
sigOut.close();