Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Java C14N Canonicalizer

807580Apr 21 2009 — edited Feb 18 2010
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!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 18 2010
Added on Apr 21 2009
2 comments
673 views