public static boolean isValidSigned(byte[] signedContent, byte[] signature, Certificate[] signingCertificateChain) {
        if (signedContent == null || signature == null || signingCertificateChain == null) {
            return false;
        }

        try {
            CMSSignedData signedData
                    = new CMSSignedData(new CMSProcessableByteArray(signedContent), new ByteArrayInputStream(signature));

            SignerInformationVerifierProvider sivp = (SignerId sid) -> {
                for (Certificate knownCert : signingCertificateChain) {
                    SignerInformationVerifier siv
                            = new JcaSimpleSignerInfoVerifierBuilder().setProvider("BC").build((X509Certificate) knownCert);
                    if (siv.getAssociatedCertificate().getIssuer().equals(sid.getIssuer())
                            && siv.getAssociatedCertificate().getSerialNumber().equals(sid.getSerialNumber())) {
                        return siv;
                    }
                }
                throw new RuntimeException("Signature was created with an unknown certificate");
            };

            return signedData.verifySignatures(sivp);
        } catch (CMSException e) {
            //Probably the signature was created with an unknown certificate or something else is wrong with the signature
            LOG.debug(e.getMessage(), e);
        } catch (Exception e) {
            LOG.debug(e.getMessage(), e);
        }
        return false;
    }
@Test
    public void isValidSignedTest() throws Exception {
        AS2SignedDataGenerator gen = SigningUtils.createSigningGenerator(AS2SignatureAlgorithm.SHA1WITHRSA,
                new Certificate[] { signingCert }, signingKP.getPrivate());
        CMSProcessableByteArray sData = new CMSProcessableByteArray(MESSAGE.getBytes(StandardCharsets.UTF_8));
        CMSSignedData signedData = gen.generate(sData, true);
        assertTrue(SigningUtils.isValidSigned(MESSAGE.getBytes(StandardCharsets.UTF_8), signedData.getEncoded(),
                new Certificate[] { signingCert }), "Message must be valid");
        assertFalse(SigningUtils.isValidSigned(MESSAGE.getBytes(StandardCharsets.UTF_8), signedData.getEncoded(),
                new Certificate[] { evilSigningCert }), "Message must be invalid");
    }