@Test public void testMultipleSignatures() throws Exception { ASN1InputStream is = new ASN1InputStream(Base64.decode(podpis1)); ASN1Primitive primitive = is.readObject(); System.out.println(org.bouncycastle.asn1.util.ASN1Dump.dumpAsString(primitive)); assertTrue(verify(podpis1) == 1); is = new ASN1InputStream(Base64.decode(podpis2)); primitive = is.readObject(); System.out.println(org.bouncycastle.asn1.util.ASN1Dump.dumpAsString(primitive)); assertTrue(verify(podpis2) == 2); }
private int verify(String signatureb64) { int verified = 0; try { CMSSignedData signature = new CMSSignedData(Base64.decode(signatureb64)); // batch verification Store certs = signature.getCertificates(); SignerInformationStore signers = signature.getSignerInfos(); Collection c = signers.getSigners(); Iterator it = c.iterator(); while (it.hasNext()) { SignerInformation signer = (SignerInformation) it.next(); Collection certCollection = certs.getMatches(signer.getSID()); Iterator certIt = certCollection.iterator(); X509CertificateHolder certHolder = (X509CertificateHolder) certIt.next(); System.out.println(verified); if (signer.verify( new JcaSimpleSignerInfoVerifierBuilder() .setProvider(new BouncyCastleProvider()) .build(certHolder))) { verified++; } } System.out.println(verified); } catch (CMSException | StoreException | CertificateException | OperatorCreationException ex) { System.err.println("error : " + ex.getMessage()); } return verified; }