Hi All,
I tried to find a way to get C14N Canonicalization functionality from Java(JRE 1.6) and was able to find only
com.sun.org.apache.xml.internal.security.c14n.Canonicalizer class. When I tried to create it(in regular java console application) using following code I got an Exception:
Canonicalizer cononicalizer = Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS);
Walking through the JDK code I discovered workaround using
com.sun.org.apache.xml.internal.security.Init class like that:
import com.sun.org.apache.xml.internal.security.Init;
import com.sun.org.apache.xml.internal.security.c14n.Canonicalizer;
class testCanonicalize
{
static
{
// XML canonicalizers must be added to hash array before we call getInstance
// Probably there is another way. I cannot found it though
(new Init()).init();
}
void createCanonicalizer()
{
try
{
Canonicalizer cononicalizer = Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS);
}
catch(InvalidCanonicalizerException ice)
{
}
}
}
Now it works fine but since com.sun.org.apache.xml.internal.security.c14n.Canonicalizer is in com.sun... package I have to explicitly set bootclasspath with rt.jar.
So,
is there another more abstract or even recommended way to have C14N functionality (without using XML signature capability) ? Since using internal classed like com.sun.org.apache.xml.internal.security.Ini is a bad practice probably good one also available :)
Thanks for your replies!