How to set a namespace prefix in a xmldisg signature?

Hello,

Currently I'm working with Visual Studio 2003 in order to generate xmldsig signature. I'm using the class signedxml to create the xmldsig signature and I get somthing like this:

<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
<CanonicalizationMethod
Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
............
</Signature>

But I need the signature to be in a namespace that should be identified by
the dsig prefix:

<dsig:Signature xmlns:dsig="http://www.w3.org/2000/09/xmldsig#">
<dsig:SignedInfo>
.....
</dsig:Signature>

How can I achive this

Any help would be greatly appreciated.
Thanks


Answer this question

How to set a namespace prefix in a xmldisg signature?

  • Frank_9

    First of all thanks for your reply.

    I'm afraid I can't modify the XML once it is created, otherwise the signature will be corrupted. That is because the TAG of the nodes are also taken into account when computing the signature so modifying its value once the signature has been created will make that the signature is no longer valid.

    So, any further idea

  • acexman

    These are functionally equivalent, so you should not have to do this.  But if you really need to do it for some reason then you can do the following XSL transform:

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
                            xmlns:dsig="http://www.w3.org/2000/09/xmldsig#">
    <
    xsl:output method="xml" indent="yes"/>
    <
    xsl:template match="/">
    <
    xsl:apply-templates select="node()"/>
    </
    xsl:template>
    <
    xsl:template match="*">
    <
    xsl:element name="dsig:{local-name()}">
    <
    xsl:apply-templates select="@*"/>
    <
    xsl:apply-templates select="node()"/>
    </
    xsl:element>
    </
    xsl:template>
    <
    xsl:template match="*[namespace-uri() != 'http://www.w3.org/2000/09/xmldsig#']">
    <
    xsl:copy>
    <
    xsl:apply-templates select="@*"/>
    <
    xsl:apply-templates select="node()"/>
    </
    xsl:copy>
    </
    xsl:template>
    <
    xsl:template match="@*">
    <
    xsl:copy >
    <
    xsl:apply-templates select="node()"/>
    </
    xsl:copy>
    </
    xsl:template>
    </
    xsl:stylesheet>

    You can run XSL transforms using the XslTransform or XslCompiledTransform classes in the System.Xml.Xsl namespace.

     


  • How to set a namespace prefix in a xmldisg signature?