java - xades4j: Sign only one element -
I am using this code to sign an XML document:
Document doc = getDocument (xml_to_sign); Element elemToSign = doc.getDocumentElement (); String file_uri_path = elemToSign.getBaseURI (); DataObjectDesc obj1 = New data object reference (file_uri_path) .withType ("http://www.gzs.si/shemas/eslog/racun/1.5#Racun"); Signed data object data obz = new signed data object (obj1); Signer.sign (Databobj, Amstosine); Xml_to_sign is the full path to xml file. The problem is, I would like to sign the node (# data) with the ID "data", but attach the signature to node elemToSign.
Is it possible to do with xades4j?
Yes, it is. Its logic is parent node , not to sign the element (it can be the same node depending on the configured references). In your example, you should add a reference to "#data": document doctor = friendly (xml_to_sign); Element origin = doc.getDocumentElement (); DataObjectDesc obj1 = New Data-Object Reference ("#data") .withType ("http://www.gzs.si/shemas/eslog/racun/1.5#Racun"); Signed data object data obz = new signed data object (obj1); Signer.sign (dataObjs, Parents);
Another option is to add a reference to the whole XML document (empty URI) and use XPath conversion.
Comments
Post a Comment