NodeList nodes
= doc.getElementsByTagNameNS(XMLSignature.XMLNS, "Signature");
DOMValidateContext dvc
= new DOMValidateContext(new X509KeySelector(), nodes.item(0));
XMLSignature signature = factory.unmarshalXMLSignature(dvc);
if (signature.validate(dvc)) {
System.err.println(
"Signature failed! Document may have been tampered with.");
}