// Step 6: Create a KeyInfo object. This step is optional, just as
// KeyInfo as an element in Signature element is optional.
KeyInfoFactory kif = fac.getKeyInfoFactory();
KeyValue kv = kif.newKeyValue(kp.getPublic());
KeyInfo ki = kif.newKeyInfo(Collections.singletonList(kv));
// Step 7: Create an XMLSignature object. In JSR-105, the XMLSignature
// interface models the Signature element of the W3C recommendation.
XMLSignature signature = fac.newXMLSignature(si, ki, Collections.singletonList(obj), null, null);