Home > Net >  How to properly change Canonicalization Method in this Java code?
How to properly change Canonicalization Method in this Java code?

Time:10-07

I'm using

import org.apache.xml.security.c14n.Canonicalizer;

in my code, and the line used to Canonicalize the signature looks like this:

outputStream.write(Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N_WITH_COMMENTS).canonicalizeSubtree(doc));

My problem is that this method leaves me with an XML file canonicalized using Method http://www.w3.org/TR/2001/REC-xml-c14n-20010315 while http://www.w3.org/2001/10/xml-exc-c14n# is what I'm being asked to do.

So, as someone absolutely new to the world of digital signatures and the like: is there a quick and easy fix I could do to achieve the desired result?

CodePudding user response:

You need to specify a canonicalization method that excludes XML comments, in this case ALGO_ID_C14N_EXCL_OMIT_COMMENTS, which translates to http://www.w3.org/2001/10/xml-exc-c14n#.

More details on the Apache Santuario library's constant field values overview.

  • Related