Class Canonicalizer


  • public class Canonicalizer
    extends java.lang.Object
    • Field Detail

      • ENCODING

        public static final java.lang.String ENCODING
        The output encoding of canonicalized data
      • XPATH_C14N_WITH_COMMENTS_SINGLE_NODE

        public static final java.lang.String XPATH_C14N_WITH_COMMENTS_SINGLE_NODE
        XPath Expression for selecting every node and continuous comments joined in only one node
        See Also:
        Constant Field Values
      • ALGO_ID_C14N_OMIT_COMMENTS

        public static final java.lang.String ALGO_ID_C14N_OMIT_COMMENTS
        The URL defined in XML-SEC Rec for inclusive c14n without comments.
        See Also:
        Constant Field Values
      • ALGO_ID_C14N_WITH_COMMENTS

        public static final java.lang.String ALGO_ID_C14N_WITH_COMMENTS
        The URL defined in XML-SEC Rec for inclusive c14n with comments.
        See Also:
        Constant Field Values
      • ALGO_ID_C14N_EXCL_OMIT_COMMENTS

        public static final java.lang.String ALGO_ID_C14N_EXCL_OMIT_COMMENTS
        The URL defined in XML-SEC Rec for exclusive c14n without comments.
        See Also:
        Constant Field Values
      • ALGO_ID_C14N_EXCL_WITH_COMMENTS

        public static final java.lang.String ALGO_ID_C14N_EXCL_WITH_COMMENTS
        The URL defined in XML-SEC Rec for exclusive c14n with comments.
        See Also:
        Constant Field Values
      • ALGO_ID_C14N11_OMIT_COMMENTS

        public static final java.lang.String ALGO_ID_C14N11_OMIT_COMMENTS
        The URI for inclusive c14n 1.1 without comments.
        See Also:
        Constant Field Values
      • ALGO_ID_C14N11_WITH_COMMENTS

        public static final java.lang.String ALGO_ID_C14N11_WITH_COMMENTS
        The URI for inclusive c14n 1.1 with comments.
        See Also:
        Constant Field Values
      • ALGO_ID_C14N_PHYSICAL

        public static final java.lang.String ALGO_ID_C14N_PHYSICAL
        Non-standard algorithm to serialize the physical representation for XML Encryption
        See Also:
        Constant Field Values
      • canonicalizerHash

        private static java.util.Map<java.lang.String,​java.lang.Class<? extends CanonicalizerSpi>> canonicalizerHash
      • secureValidation

        private boolean secureValidation
    • Method Detail

      • register

        public static void register​(java.lang.String algorithmURI,
                                    java.lang.String implementingClass)
                             throws AlgorithmAlreadyRegisteredException,
                                    java.lang.ClassNotFoundException
        Method register
        Parameters:
        algorithmURI -
        implementingClass -
        Throws:
        AlgorithmAlreadyRegisteredException
        java.lang.SecurityException - if a security manager is installed and the caller does not have permission to register the canonicalizer
        java.lang.ClassNotFoundException
      • register

        public static void register​(java.lang.String algorithmURI,
                                    java.lang.Class<? extends CanonicalizerSpi> implementingClass)
                             throws AlgorithmAlreadyRegisteredException,
                                    java.lang.ClassNotFoundException
        Method register
        Parameters:
        algorithmURI -
        implementingClass -
        Throws:
        AlgorithmAlreadyRegisteredException
        java.lang.SecurityException - if a security manager is installed and the caller does not have permission to register the canonicalizer
        java.lang.ClassNotFoundException
      • registerDefaultAlgorithms

        public static void registerDefaultAlgorithms()
        This method registers the default algorithms.
      • getURI

        public final java.lang.String getURI()
        Method getURI
        Returns:
        the URI defined for this c14n instance.
      • getIncludeComments

        public boolean getIncludeComments()
        Method getIncludeComments
        Returns:
        true if the c14n respect the comments.
      • canonicalize

        public byte[] canonicalize​(byte[] inputBytes)
                            throws javax.xml.parsers.ParserConfigurationException,
                                   java.io.IOException,
                                   org.xml.sax.SAXException,
                                   CanonicalizationException
        This method tries to canonicalize the given bytes. It's possible to even canonicalize non-wellformed sequences if they are well-formed after being wrapped with a >a<...>/a<.
        Parameters:
        inputBytes -
        Returns:
        the result of the canonicalization.
        Throws:
        CanonicalizationException
        java.io.IOException
        javax.xml.parsers.ParserConfigurationException
        org.xml.sax.SAXException
      • canonicalizeSubtree

        public byte[] canonicalizeSubtree​(org.w3c.dom.Node node)
                                   throws CanonicalizationException
        Canonicalizes the subtree rooted by node.
        Parameters:
        node - The node to canonicalize
        Returns:
        the result of the c14n.
        Throws:
        CanonicalizationException
      • canonicalizeSubtree

        public byte[] canonicalizeSubtree​(org.w3c.dom.Node node,
                                          java.lang.String inclusiveNamespaces)
                                   throws CanonicalizationException
        Canonicalizes the subtree rooted by node.
        Parameters:
        node -
        inclusiveNamespaces -
        Returns:
        the result of the c14n.
        Throws:
        CanonicalizationException
      • canonicalizeSubtree

        public byte[] canonicalizeSubtree​(org.w3c.dom.Node node,
                                          java.lang.String inclusiveNamespaces,
                                          boolean propagateDefaultNamespace)
                                   throws CanonicalizationException
        Canonicalizes the subtree rooted by node.
        Parameters:
        node -
        inclusiveNamespaces -
        Returns:
        the result of the c14n.
        Throws:
        CanonicalizationException
      • canonicalizeXPathNodeSet

        public byte[] canonicalizeXPathNodeSet​(org.w3c.dom.NodeList xpathNodeSet)
                                        throws CanonicalizationException
        Canonicalizes an XPath node set. The xpathNodeSet is treated as a list of XPath nodes, not as a list of subtrees.
        Parameters:
        xpathNodeSet -
        Returns:
        the result of the c14n.
        Throws:
        CanonicalizationException
      • canonicalizeXPathNodeSet

        public byte[] canonicalizeXPathNodeSet​(org.w3c.dom.NodeList xpathNodeSet,
                                               java.lang.String inclusiveNamespaces)
                                        throws CanonicalizationException
        Canonicalizes an XPath node set. The xpathNodeSet is treated as a list of XPath nodes, not as a list of subtrees.
        Parameters:
        xpathNodeSet -
        inclusiveNamespaces -
        Returns:
        the result of the c14n.
        Throws:
        CanonicalizationException
      • canonicalizeXPathNodeSet

        public byte[] canonicalizeXPathNodeSet​(java.util.Set<org.w3c.dom.Node> xpathNodeSet)
                                        throws CanonicalizationException
        Canonicalizes an XPath node set.
        Parameters:
        xpathNodeSet -
        Returns:
        the result of the c14n.
        Throws:
        CanonicalizationException
      • canonicalizeXPathNodeSet

        public byte[] canonicalizeXPathNodeSet​(java.util.Set<org.w3c.dom.Node> xpathNodeSet,
                                               java.lang.String inclusiveNamespaces)
                                        throws CanonicalizationException
        Canonicalizes an XPath node set.
        Parameters:
        xpathNodeSet -
        inclusiveNamespaces -
        Returns:
        the result of the c14n.
        Throws:
        CanonicalizationException
      • setWriter

        public void setWriter​(java.io.OutputStream os)
        Sets the writer where the canonicalization ends. ByteArrayOutputStream if none is set.
        Parameters:
        os -
      • getImplementingCanonicalizerClass

        public java.lang.String getImplementingCanonicalizerClass()
        Returns the name of the implementing CanonicalizerSpi class
        Returns:
        the name of the implementing CanonicalizerSpi class
      • notReset

        public void notReset()
        Set the canonicalizer behaviour to not reset.
      • isSecureValidation

        public boolean isSecureValidation()
      • setSecureValidation

        public void setSecureValidation​(boolean secureValidation)