use of javax.xml.crypto.dsig.XMLSignature in project simba-os by cegeka.
the class Utils method validateSign.
/**
* Validate signature (Message or Assertion).
*
* @param signatureElement The element we should validate
* @param cert The pubic cert
* @param fingerprint The fingerprint of the public cert
* @return True if the sign is valid, false otherwise.
*/
public static boolean validateSign(Node signatureElement, Certificate cert, String... fingerprint) throws Exception {
boolean res;
DOMValidateContext ctx = new DOMValidateContext(cert.getPublicKey(), signatureElement);
XMLSignatureFactory sigF = XMLSignatureFactory.getInstance("DOM");
try {
XMLSignature xmlSignature = sigF.unmarshalXMLSignature(ctx);
res = xmlSignature.validate(ctx);
} catch (MarshalException e) {
log.error("Cannot locate Signature Node " + e.getMessage(), e);
throw e;
} catch (NullPointerException e) {
log.error("Context can't be validated", e);
throw e;
}
return res;
}
Aggregations