// Create the signed CMS message to be contained inside the envelope
// this message does not contain any message, and no signerInfo
CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
gen.addCertificatesAndCRLs(certs);
CMSSignedData s = gen.generate(null, false, "BC");
// Envelope the CMS message
if (recipientKeyInfo != null) {
try {
X509Certificate rec = (X509Certificate)CertTools.getCertfromByteArray(recipientKeyInfo);
log.debug("Added recipient information - issuer: '" + CertTools.getIssuerDN(rec) + "', serno: '" + CertTools.getSerialNumberAsString(rec));
edGen.addKeyTransRecipient(rec);
} catch (CertificateException e) {
throw new IOException("Can not decode recipients self signed certificate!");
}
} else {
edGen.addKeyTransRecipient((X509Certificate) cert);
}
CMSEnvelopedData ed = edGen.generate(new CMSProcessableByteArray(s.getEncoded()),
SMIMECapability.dES_CBC.getId(), "BC");
log.debug("Enveloped data is " + ed.getEncoded().length + " bytes long");
msg = new CMSProcessableByteArray(ed.getEncoded());
} else {