response = response.replaceFirst("-----BEGIN PKCS7-----", "").replaceFirst("-----END PKCS7-----", "");
byte[] responseData = Base64.decode(response.getBytes());
X509Certificate returnCertificate= null;
CMSSignedData p7b = new CMSSignedData(responseData);
CertStore certStore = p7b.getCertificatesAndCRLs("Collection", "BC");
SignerInformationStore signers = p7b.getSignerInfos();
Iterator<SignerInformation> iter = signers.getSigners().iterator();
while (iter.hasNext())
{
SignerInformation signer = iter.next();
X509Certificate caCert = (X509Certificate) certStore.getCertificates(signer.getSID()).iterator().next();
Iterator<? extends Certificate> iter2 = certStore.getCertificates(null).iterator();