|
Java™ by example!
|
|
|
How do I canonicalize an XML file?
The canonical form of an XML document is a normalized version of that XML document. Two XML documents that are physically different can still be logically the same. For example, consider an XML tag with two attributes. The order in which the attributes appear is of no importance:
The canonical form of an XML document is important when you look at signing. Signing an XML document consists of calculating a message digest (hash) to ensure message integrity and signing the message and the hash with the private key of the sender. The receiver would then use the public key to verify. The verification procedure should go successful regardless of the physical representation of the XML document. This is where the problem comes in: the digest of example (1) is different than the digest of example (2), even though the information is the same. It is important to calculate the message digest on the canonical form of the XML document. More information about canonical XML can be found here. The following example uses the Canonicalizer class from the XML Security project at apache.org. Download it here and place the following libraries in your classpath:
Main.java:
outputs:
Further Information
Author of answer: Joris Van den Bogaert
Comments
Comments to this answer are only viewable by members. Login or become a member!
|
|
|
|
|