{
RecipientInformation ri = (RecipientInformation) recipCertificatesIt.next();
// Impl: if a matching certificate was previously found it is an error,
// here we just don't care about it
X509Certificate certificate = material.getCertificate();
X509CertificateHolder materialCert = null;
if (null != certificate)
{
materialCert = new X509CertificateHolder(certificate.getEncoded());
}
RecipientId rid = ri.getRID();
if (rid.match(materialCert) && !foundRecipient)
{
foundRecipient = true;
PrivateKey privateKey = (PrivateKey) material.getPrivateKey();
envelopedData = ri.getContent(new JceKeyTransEnvelopedRecipient(privateKey).setProvider("BC"));
break;
}
j++;
if ((verbose || LOG.isDebugEnabled()) && certificate != null)
{
extraInfo += "\n" + j + ": ";
if (rid instanceof KeyTransRecipientId)
{
KeyTransRecipientId ktRid = (KeyTransRecipientId) rid;
BigInteger ridSerialNumber = ktRid.getSerialNumber();
if (ridSerialNumber != null)
{
String certSerial = "unknown";
BigInteger certSerialNumber = certificate.getSerialNumber();
if (certSerialNumber != null)
{
certSerial = certSerialNumber.toString(16);
}
extraInfo += "serial-#: rid " + ridSerialNumber.toString(16)
+ " vs. cert " + certSerial + " issuer: rid \'"
+ ktRid.getIssuer() + "\' vs. cert \'"
+ (materialCert == null ? "null" : materialCert.getIssuer()) + "\' ";
}
}
}
}
recipientFieldsBytes[i] = recipientBytes;