I am failing to understand how to place the signature node as a sibling to the data node. The example that I have found was from Oracle, but only covered the normal detached signature, where the XML is passed as an URI to the Reference object.
Reference to the Oracle example: https://docs.oracle.com/javase/8/docs/technotes/guides/security/xmldsig/GenDetached.java
One way to do this is as follows:
Step 1 - get the signature XML as a string.
Change the sample
GenDetachedcode in your link as follows, so that the output is a string.The following changes are made at the bottom of the class:
Also change the method signature so it returns a string - for example:
Step 2 - Add the signature data to your target XML document.
Assume we have the following target doc:
The following code extracts the
<Signature>node from the signature XML and adds it as a child of the<root>node in your document:The result is this (details omitted):
Hope that helps.
Small point about the "internally detached" terminology in the question (courtesy of Wikipedia):
I assume this example is the latter.