Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8015693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:19:26+00:00 2026-06-04T20:19:26+00:00

I have a XML document.I am signing a part of document using xmlsignature. Before

  • 0

I have a XML document.I am signing a part of document using xmlsignature. Before finding digest, I want to apply XSLT transform.

According to what I read, XSLT converts an XML document to another format(can be XML also). Now I am confused that,
where will be the transformed new document is avilable?

How to retrieve the value from this newly created document if I want to show it to user?

My XML Document

<r1>
 <user>asd</user>
 <person>ghi</person>
</r1>

Code for Transformation

Transform t=fac.newTransform(Transform.XPATH,new XPathFilterParameterSpec("/r1/user"));

According to xpath transformation,Whenever value of user element changes the xmlsignature should not be validated. And if person element’s value changes then Signature should be validated. But when I change person element’s value the signature is not validated. WHY?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T20:19:28+00:00Added an answer on June 4, 2026 at 8:19 pm

    The xslt transform used when signing a document relates to how nodes in your source XML are selected when the signature is calculated.

    This question/answer by Dave relates to signing parts of an XML document using xpath2. The link to Sean Mullans’ post in this answer suggests xpath2 is more appropriate for signing parts of a document because the evaluation of an xpath expression is done per node.

    So based on the sun dsig example you can replace the Reference creation using:

    List<XPathType> xpaths = new ArrayList<XPathType>();
    xpaths.add(new XPathType("//r1/user", XPathType.Filter.INTERSECT));
    
    Reference ref = fac.newReference
      ("", fac.newDigestMethod(DigestMethod.SHA1, null),
            Collections.singletonList
              (fac.newTransform(Transform.XPATH2, 
                      new XPathFilter2ParameterSpec(xpaths))),
                 null, null); 
    

    This allows //r1/user to be protected with a signature while the rest of the document can be altered.

    The problem with the xpath/xpath2 selection is that a signature can be generated for /some/node/that/does/not/exist. You are right to modify a test document and make sure the signature is working the way you expect.

    You might test the document in a test program by generating a signature then tampering with the xml node before verification:

    NodeList nlt = doc.getElementsByTagName("user");
    nlt.item(0).getFirstChild().setTextContent("Something else");
    

    A more reliable alternative to an xpath selector might be to put an ID on the xml document elements you hope to sign like:

    <r1>
     <user id="sign1">asd</user>
     <person>ghi</person>
    </r1>
    

    then reference this ID as the URI in the first parameter of an enveloped transfer:

    Reference ref = fac.newReference
      ("#sign1", fac.newDigestMethod(DigestMethod.SHA1, null),
        Collections.singletonList
          (fac.newTransform(Transform.ENVELOPED,(TransformParameterSpec) null)),
              null, null); 
    

    For the output, a signature operation adds a new Signature element to the DOM you have loaded in memory. You can stream the output by transforming it like this:

    TransformerFactory tf = TransformerFactory.newInstance();
    Transformer trans = tf.newTransformer();
    trans.setOutputProperty(OutputKeys.INDENT, "yes");
    
    trans.transform(new DOMSource(doc), new StreamResult(System.out)); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML document with un-namespaced elements, and I want to use XSLT
I have this XML document and I want to find an specific GitHubCommiter using
I have an XML document, and I want to print the tag names and
I have an XML document with companies listed in it. I want to create
I have an xml document (using the Document class in the XMLParser library of
I want to update an XML document in my xml database (Marklogic). I have
I have a XML document. From the whole document I want to parse a
I have some XML document with <item> elements, and i'd want to wrap each
I have an xml document as a string without any namespace and I want
I have an xml document. When parsing that doc I want to do <c:set

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.