src/main/java/org/edgegallery/appstore/infrastructure/util/Signature.java
public static boolean signedDataVerify(byte[] signedData) throws CMSException {
        CMSSignedData cmsData = new CMSSignedData(Base64.decode(signedData));
        Store<X509CertificateHolder> store = cmsData.getCertificates();
        SignerInformationStore signerInfo = cmsData.getSignerInfos();
        Collection<SignerInformation> signers = signerInfo.getSigners();
        Iterator<SignerInformation> iterator = signers.iterator();
        while (iterator.hasNext()) {
            SignerInformation signer = iterator.next();
            Collection<X509CertificateHolder> certs = store.getMatches(signer.getSID());
            Iterator<X509CertificateHolder> certIterator = certs.iterator();
            X509CertificateHolder certHolder = certIterator.next();
            X509Certificate cert;
            try {
                cert = new JcaX509CertificateConverter().setProvider("BC").getCertificate(certHolder);
                if (signer.verify(new JcaSimpleSignerInfoVerifierBuilder().setProvider("BC").build(cert))) {
                    return true;
                }
            } catch (CertificateException e) {
                LOGGER.error("certificate exception, {}", e.getMessage());
            } catch (OperatorCreationException e) {
                LOGGER.error("operator create exception, {}", e.getMessage());
            }
        }
        LOGGER.error("check signed data invalid.");
        return false;
    }
/**
     * verify signature value.
     *
     * @param signedData signature value
     * @return if verify sucess
     * @throws CMSException CMSException
     */
verify signature value.
@param signedData signature value
@return if verify sucess
@throws CMSException CMSException
verify signature value . @param signedData signature value @return if verify sucess @throws CMSException CMSException
public static boolean signedDataVerify(byte[] signedData) throws CMSException {
        CMSSignedData cmsData = new CMSSignedData(Base64.decode(signedData));
        Store<X509CertificateHolder> store = cmsData.getCertificates();
        SignerInformationStore signerInfo = cmsData.getSignerInfos();
        Collection<SignerInformation> signers = signerInfo.getSigners();
        Iterator<SignerInformation> iterator = signers.iterator();
        while (iterator.hasNext()) {
            SignerInformation signer = iterator.next();
            Collection<X509CertificateHolder> certs = store.getMatches(signer.getSID());
            Iterator<X509CertificateHolder> certIterator = certs.iterator();
            X509CertificateHolder certHolder = certIterator.next();
            X509Certificate cert;
            try {
                cert = new JcaX509CertificateConverter().setProvider("BC").getCertificate(certHolder);
                if (signer.verify(new JcaSimpleSignerInfoVerifierBuilder().setProvider("BC").build(cert))) {
                    return true;
                }
            } catch (CertificateException e) {
                LOGGER.error("certificate exception, {}", e.getMessage());
            } catch (OperatorCreationException e) {
                LOGGER.error("operator create exception, {}", e.getMessage());
            }
        }
        LOGGER.error("check signed data invalid.");
        return false;
    }
public static boolean signedDataVerify ( byte [ ] signedData ) throws CMSException { CMSSignedData cmsData = new CMSSignedData ( Base64 . decode ( signedData ) ) ; Store < X509CertificateHolder > store = cmsData . getCertificates ( ) ; SignerInformationStore signerInfo = cmsData . getSignerInfos ( ) ; Collection < SignerInformation > signers = signerInfo . getSigners ( ) ; Iterator < SignerInformation > iterator = signers . iterator ( ) ; while ( iterator . hasNext ( ) ) { SignerInformation signer = iterator . next ( ) ; Collection < X509CertificateHolder > certs = store . getMatches ( signer . getSID ( ) ) ; Iterator < X509CertificateHolder > certIterator = certs . iterator ( ) ; X509CertificateHolder certHolder = certIterator . next ( ) ; X509Certificate cert ; try { cert = new JcaX509CertificateConverter ( ) . setProvider ( "BC" ) . getCertificate ( certHolder ) ; if ( signer . verify ( new JcaSimpleSignerInfoVerifierBuilder ( ) . setProvider ( "BC" ) . build ( cert ) ) ) { return true ; } } catch ( CertificateException e ) { LOGGER . error ( "certificate exception, {}" , e . getMessage ( ) ) ; } catch ( OperatorCreationException e ) { LOGGER . error ( "operator create exception, {}" , e . getMessage ( ) ) ; } } LOGGER . error ( "check signed data invalid." ) ; return false ; }
verify signature value.
verify signature value .