I have a pkcs7 SignedData(see my attachment), it can't be validated by Bouncy Castle with follow code:
//load data from my attached file
FileInputStream file = new FileInputStream("SignedData.bin.txt");
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length;
while((length = file.read(buffer)) > 0)
{
out.write(buffer, 0, length);
}
out.flush();
byte[] encapSigData = out.toByteArray();
out.close();
//validate the SignedData CMSSignedDataParser sp = new CMSSignedDataParser(new JcaDigestCalculatorProviderBuilder().setProvider("BC").build(), encapSigData);
sp.getSignedContent().drain();
Store certStore = sp.getCertificates();
SignerInformationStore signers = sp.getSignerInfos();
Collection c = signers.getSigners();
Iterator it = c.iterator();
while (it.hasNext())
{
SignerInformation signer = (SignerInformation)it.next();
Collection certCollection = certStore.getMatches(signer.getSID());
Iterator certIt = certCollection.iterator();
X509CertificateHolder cert = (X509CertificateHolder)certIt.next();
System.out.println("verify returns: " + signer.verify(new JcaSimpleSignerInfoVerifierBuilder().setProvider("BC").build(cert)));
}
Exception occurred at CMSSignedDataParser constructor:
java.lang.ClassCastException: org.bouncycastle.asn1.DERSequenceParser cannot be cast to org.bouncycastle.asn1.ASN1OctetStringParser
at org.bouncycastle.cms.CMSSignedDataParser.<init>(Unknown Source)
at org.bouncycastle.cms.CMSSignedDataParser.<init>(Unknown Source)
at org.bouncycastle.cms.CMSSignedDataParser.<init>(Unknown Source)
After some analysis, I find that the content of contentInfo in SignedData is a Sequence. It seems that bouncycastle can't accept a Sequence to be the content.
More details in stackoverflow: http://stackoverflow.com/questions/34197756/validate-pkcs7-signeddata-by-bouncy-castle-in-java
SignedData.bin.txt
I have a pkcs7 SignedData(see my attachment), it can't be validated by Bouncy Castle with follow code:
Exception occurred at
CMSSignedDataParserconstructor:After some analysis, I find that the content of contentInfo in SignedData is a Sequence. It seems that bouncycastle can't accept a Sequence to be the content.
More details in stackoverflow: http://stackoverflow.com/questions/34197756/validate-pkcs7-signeddata-by-bouncy-castle-in-java
SignedData.bin.txt