public static boolean validSignature(Document document, Key publicKey) {
        Node signatureNode = document.getElementsByTagNameNS(XMLSignature.XMLNS, "Signature").item(0);
        KeySelector keySelector = KeySelector.singletonKeySelector(publicKey);

        try {
            String providerName =
                    System.getProperty("jsr105Provider", "org.jcp.xml.dsig.internal.dom.XMLDSigRI");
            XMLSignatureFactory fac = XMLSignatureFactory.getInstance("DOM",
                    (Provider) Class.forName(providerName).newInstance());
            DOMValidateContext valContext = new DOMValidateContext(keySelector, signatureNode);

            XMLSignature signature = fac.unmarshalXMLSignature(valContext);
            return signature.validate(valContext);
        } catch (Exception e) {
            logger.warn("Error validating an XML signature.", e);
            return false;
        }
    }
public static boolean validSignature(Document document, Key publicKey) {
        Node signatureNode = document.getElementsByTagNameNS(XMLSignature.XMLNS, "Signature").item(0);
        KeySelector keySelector = KeySelector.singletonKeySelector(publicKey);

        try {
            String providerName =
                    System.getProperty("jsr105Provider", "org.jcp.xml.dsig.internal.dom.XMLDSigRI");
            XMLSignatureFactory fac = XMLSignatureFactory.getInstance("DOM",
                    (Provider) Class.forName(providerName).newInstance());
            DOMValidateContext valContext = new DOMValidateContext(keySelector, signatureNode);

            XMLSignature signature = fac.unmarshalXMLSignature(valContext);
            return signature.validate(valContext);
        } catch (Exception e) {
            logger.warn("Error validating an XML signature.", e);
            return false;
        }
    }
public static boolean validSignature ( Document document , Key publicKey ) { Node signatureNode = document . getElementsByTagNameNS ( XMLSignature . XMLNS , "Signature" ) . item ( 0 ) ; KeySelector keySelector = KeySelector . singletonKeySelector ( publicKey ) ; try { String providerName = System . getProperty ( "jsr105Provider" , "org.jcp.xml.dsig.internal.dom.XMLDSigRI" ) ; XMLSignatureFactory fac = XMLSignatureFactory . getInstance ( "DOM" , ( Provider ) Class . forName ( providerName ) . newInstance ( ) ) ; DOMValidateContext valContext = new DOMValidateContext ( keySelector , signatureNode ) ; XMLSignature signature = fac . unmarshalXMLSignature ( valContext ) ; return signature . validate ( valContext ) ; } catch ( Exception e ) { logger . warn ( "Error validating an XML signature." , e ) ; return false ; } }
Check the xmldsig signature of the XML document.

@param document  the document to test
@param publicKey the public key corresponding to the key pair the document was signed with
@return true if a correct signature is present, false otherwise
Check the xmldsig signature of the XML document .