In the code below, I call sign() against a new DataObjectReference( "" ).
This means Xades4j calculates the digest against the whole Document object.
But this also means it strips any whitespace, as the Document object doesn't contain whitespace information.
I tried using an AnonymousDataObjectReference instead (passing the string-serialized XML) but then the (XPath) Transform fails to parse the string.
I'd like to be able to pass a pretty-printed document to Xades4j, so that the output hash matches the final pretty-printed document hash.
KeyingDataProvider kp = loadKeyStore();
DataObjectDesc obj = new DataObjectReference( "" )
.withTransform( /*[...]*/ )
.withDataObjectFormat( new DataObjectFormatProperty( MediaType.TEXT_XML ) );
try
{
XadesSigner signer = new XadesBesSigningProfile( kp )
.newSigner();
Node signatureInformation = doc.getElementsByTagName( "sac:SignatureInformation" ).item( 0 );
XadesSignatureResult signResult = signer.sign( new SignedDataObjects( obj ), signatureInformation );
return signResult;
}
catch ( XAdES4jException e )
{
//...
}