Examples of Canonicalizer


Examples of org.apache.xml.security.c14n.Canonicalizer

      DocumentBuilder db = dfactory.newDocumentBuilder();
      Document doc = db.parse(new ByteArrayInputStream(inputStr.getBytes()));
      boolean weCatchedTheRelativeNS = false;

      try {
         Canonicalizer c14n =
            Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS);
         byte c14nBytes[] = c14n.canonicalizeSubtree(doc);

         /*
         FileOutputStream fos = new FileOutputStream("data/org/apache/xml/security/out/relativeNS.xml");
         fos.write(c14nBytes);
         fos.close();
View Full Code Here

Examples of org.apache.xml.security.c14n.Canonicalizer

                  InvalidCanonicalizerException, TransformerException {

      String val =
         "<UTF16>The german &amp;auml (which is Unicode &amp;#xE4;):  &quot;&#xE4;&quot;</UTF16>";
      byte utf16[] = convertToUTF16(val.getBytes());
      Canonicalizer c14n =
         Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS);
      byte c14nBytes[] = c14n.canonicalize(utf16);
      org.xml.sax.EntityResolver resolver = new TestVectorResolver();
      InputStream refStream = resolver.resolveEntity(
         null,
            "data/org/apache/xml/security/c14n/in/testTranslationFromUTF16toUTF8.xml")
               .getByteStream();
View Full Code Here

Examples of org.apache.xml.security.c14n.Canonicalizer

      db.setErrorHandler(new org.apache.xml.security.utils
         .IgnoreAllErrorHandler());

      Document doc = db.parse(new ByteArrayInputStream(input.getBytes()));
      Canonicalizer c14nizer =
         Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS);
      CachedXPathAPI xpathAPI = new CachedXPathAPI();

      XMLUtils.circumventBug2650(doc);

      NodeList nodes =
         xpathAPI.selectNodeList(doc, "(//*[local-name()='included'] | //@*[parent::node()[local-name()='included']])");
      byte result[] = c14nizer.canonicalizeXPathNodeSet(nodes);
      byte defined[] = definedOutput.getBytes();

      if (writeResultsToFile) {
         File fileD = new File("defined.txt");
         FileOutputStream fd = new FileOutputStream(fileD);
View Full Code Here

Examples of org.apache.xml.security.c14n.Canonicalizer

      // Document doc = documentBuilder.parse(resolver.resolveEntity(null, fileIn));
      Document doc = documentBuilder.parse(fileIn);

      XMLUtils.circumventBug2650(doc);

      Canonicalizer c14n = Canonicalizer.getInstance(c14nURI);
      byte c14nBytes[] = null;

      if (xpath == null) {
         c14nBytes = c14n.canonicalizeSubtree(doc);
      } else {
         CachedXPathAPI xpathAPI = new CachedXPathAPI();
         NodeList nl = null;

         if (xpath instanceof String) {
            nl = xpathAPI.selectNodeList(doc, (String) xpath);
         } else {
            Element xpathElement = (Element) xpath;
            String xpathStr = ((Text) xpathElement.getFirstChild()).getData();

            nl = xpathAPI.selectNodeList(doc, xpathStr, xpathElement);
         }

         c14nBytes = c14n.canonicalizeXPathNodeSet(nl);
      }

      // org.xml.sax.InputSource refIs = resolver.resolveEntity(null, fileRef);
      // byte refBytes[] = JavaUtils.getBytesFromStream(refIs.getByteStream());
      byte refBytes[] = JavaUtils.getBytesFromFile(fileRef);
View Full Code Here

Examples of org.apache.xml.security.c14n.Canonicalizer

      // org.xml.sax.EntityResolver resolver = new TestVectorResolver();
      // documentBuilder.setEntityResolver(resolver);
      // Document doc = documentBuilder.parse(resolver.resolveEntity(null, fileIn));
      Document doc = documentBuilder.parse(fileIn);
      XMLUtils.circumventBug2650(doc);
      Canonicalizer c14n = Canonicalizer.getInstance(c14nURI);
      byte c14nBytes[] = null;

      if (xpath == null) {
         c14nBytes = c14n.canonicalizeSubtree(doc);
      } else {
         CachedXPathAPI xpathAPI = new CachedXPathAPI();
         NodeList nl = null;

         if (xpath instanceof String) {
            nl = xpathAPI.selectNodeList(doc, (String) xpath);
         } else {
            Element xpathElement = (Element) xpath;
            String xpathStr = ((Text) xpathElement.getFirstChild()).getData();

            nl = xpathAPI.selectNodeList(doc, xpathStr, xpathElement);
         }

         c14nBytes = c14n.canonicalizeXPathNodeSet(nl);
      }

      // org.xml.sax.InputSource refIs = resolver.resolveEntity(null, fileRef);
      // byte refBytes[] = JavaUtils.getBytesFromStream(refIs.getByteStream());
      byte refBytes[] = JavaUtils.getBytesFromFile(fileRef);
View Full Code Here

Examples of org.apache.xml.security.c14n.Canonicalizer

      db.setErrorHandler(new org.apache.xml.security.utils
         .IgnoreAllErrorHandler());

      Document doc = db.parse(new ByteArrayInputStream(input.getBytes()));
      Canonicalizer c14nizer =
         Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS);
      CachedXPathAPI xpathAPI = new CachedXPathAPI();
      XMLUtils.circumventBug2650(doc);
      NodeList nodes =
         xpathAPI.selectNodeList(doc, "(//*[local-name()='included'] | //@*)");
      byte result[] = c14nizer.canonicalizeXPathNodeSet(nodes);
      byte defined[] = definedOutput.getBytes();

      if (writeResultsToFile) {
         File fileD = new File("defined.txt");
         FileOutputStream fd = new FileOutputStream(fileD);
View Full Code Here

Examples of org.apache.xml.security.c14n.Canonicalizer

      c14nMethodURI.equals(Canonicalizer.ALGO_ID_C14N11_OMIT_COMMENTS) ||
      c14nMethodURI.equals(Canonicalizer.ALGO_ID_C14N11_WITH_COMMENTS))) {
            // the c14n is not a secure one and can rewrite the URIs or like
      // so reparse the SignedInfo to be sure   
            try {
                Canonicalizer c14nizer =
                    Canonicalizer.getInstance(c14nMethodURI);

                byte[] c14nizedBytes = c14nizer.canonicalizeSubtree(element);
                javax.xml.parsers.DocumentBuilderFactory dbf =
                    javax.xml.parsers.DocumentBuilderFactory.newInstance();
                dbf.setNamespaceAware(true);
                javax.xml.parsers.DocumentBuilder db = dbf.newDocumentBuilder();       
                Document newdoc =
View Full Code Here

Examples of org.apache.xml.security.c14n.Canonicalizer

    public byte[] getCanonicalizedOctetStream()
           throws CanonicalizationException, InvalidCanonicalizerException,
                 XMLSecurityException {

        if (this._c14nizedBytes == null) {
            Canonicalizer c14nizer =
                Canonicalizer.getInstance(this.getCanonicalizationMethodURI());

            this._c14nizedBytes =
                c14nizer.canonicalizeSubtree(this._constructionElement);
        }

        // make defensive copy
        return (byte[]) this._c14nizedBytes.clone();
    }
View Full Code Here

Examples of org.apache.xml.security.c14n.Canonicalizer

    public void signInOctectStream(OutputStream os)           
        throws CanonicalizationException, InvalidCanonicalizerException,
            XMLSecurityException {

     if (this._c14nizedBytes == null) {
            Canonicalizer c14nizer =
                Canonicalizer.getInstance(this.getCanonicalizationMethodURI());
            c14nizer.setWriter(os);
            String inclusiveNamespaces = this.getInclusiveNamespaces();

            if (inclusiveNamespaces == null) {
                c14nizer.canonicalizeSubtree(this._constructionElement);
            } else {
                c14nizer.canonicalizeSubtree
                    (this._constructionElement, inclusiveNamespaces);
            }
        } else {
            try {
    os.write(this._c14nizedBytes);
View Full Code Here

Examples of org.apache.xml.security.c14n.Canonicalizer

      sig.getKeyInfo().addKeyName("The UTF-8 octets of \"" + secretKey
                                  + "\" are used for signing ("
                                  + secretKey.length() + " octets)");
      sig.sign(sig.createSecretKey(secretKey.getBytes()));

      Canonicalizer c14n =
         Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N_WITH_COMMENTS);
      byte[] full = c14n.canonicalizeSubtree(doc);
      byte[] ref = sig.getSignedInfo().item(0).getTransformsOutput().getBytes();
      byte[][] result = {
         full, ref
      };
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.