473,549 Members | 2,644 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to add a namespace prefix to a digital signature

Hello,

I use a code very similar to that found in the MSDN sample attached to the
class XmlDsigEnvelope dSignatureTrans form (code attached below).
The code works fine and produces somethink like
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
<Canonicalizati onMethod
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 ds prefix:

<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:SignedInf o>
.....
</ds:Signature>

How can I achive this?

Any help would be greatly appreciated
Code that I use:

// Sign an XML file and save the signature in a new file.
public static void SignXmlFile(str ing FileName, string SignedFileName,
RSA Key)
{
// Create a new XML document.
XmlDocument doc = new XmlDocument();

// Format the document to ignore white spaces.
doc.PreserveWhi tespace = false;

// Load the passed XML file using it's name.
doc.Load(new XmlTextReader(F ileName));

// Create a SignedXml object.
SignedXml signedXml = new SignedXml(doc);

// Add the key to the SignedXml document.
signedXml.Signi ngKey = Key;

// Create a reference to be signed.
Reference reference = new Reference();
reference.Uri = "";

// Add a transformation to the reference.
Transform trns = new XmlDsigC14NTran sform();
reference.AddTr ansform(trns);

// Add an enveloped transformation to the reference.
XmlDsigEnvelope dSignatureTrans form env = new
XmlDsigEnvelope dSignatureTrans form();
reference.AddTr ansform(env);

// Add the reference to the SignedXml object.
signedXml.AddRe ference(referen ce);
// Add an RSAKeyValue KeyInfo (optional; helps recipient find key to
validate).
KeyInfo keyInfo = new KeyInfo();
keyInfo.AddClau se(new RSAKeyValue((RS A)Key));
signedXml.KeyIn fo = keyInfo;

// Compute the signature.
signedXml.Compu teSignature();

// Get the XML representation of the signature and save
// it to an XmlElement object.
XmlElement xmlDigitalSigna ture = signedXml.GetXm l();

// Append the element to the XML document.
doc.DocumentEle ment.AppendChil d(doc.ImportNod e(xmlDigitalSig nature,
true));
if (doc.FirstChild is XmlDeclaration)
{
doc.RemoveChild (doc.FirstChild );
}

// Save the signed XML document to a file specified
// using the passed string.
XmlTextWriter xmltw = new XmlTextWriter(S ignedFileName, new
UTF8Encoding(fa lse));
doc.WriteTo(xml tw);
xmltw.Close();
}
Nov 12 '05 #1
2 10232
I solved it myself

Void ChangePrefix (XmlNode ^ pNode)
{
if ( !pNode)
return;

do
{
pNode->Prefix = "ds";

ChangePrefix (pNode->FirstChild);
}
while ( pNode = pNode->NextSibling );
}
"S. Baumann" <no*****@xyz.co m> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Hello,

I use a code very similar to that found in the MSDN sample attached to the
class XmlDsigEnvelope dSignatureTrans form (code attached below).
The code works fine and produces somethink like
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
<Canonicalizati onMethod
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 ds prefix:

<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:SignedInf o>
....
</ds:Signature>

How can I achive this?

Any help would be greatly appreciated
Code that I use:

// Sign an XML file and save the signature in a new file.
public static void SignXmlFile(str ing FileName, string SignedFileName,
RSA Key)
{
// Create a new XML document.
XmlDocument doc = new XmlDocument();

// Format the document to ignore white spaces.
doc.PreserveWhi tespace = false;

// Load the passed XML file using it's name.
doc.Load(new XmlTextReader(F ileName));

// Create a SignedXml object.
SignedXml signedXml = new SignedXml(doc);

// Add the key to the SignedXml document.
signedXml.Signi ngKey = Key;

// Create a reference to be signed.
Reference reference = new Reference();
reference.Uri = "";

// Add a transformation to the reference.
Transform trns = new XmlDsigC14NTran sform();
reference.AddTr ansform(trns);

// Add an enveloped transformation to the reference.
XmlDsigEnvelope dSignatureTrans form env = new
XmlDsigEnvelope dSignatureTrans form();
reference.AddTr ansform(env);

// Add the reference to the SignedXml object.
signedXml.AddRe ference(referen ce);
// Add an RSAKeyValue KeyInfo (optional; helps recipient find key
to validate).
KeyInfo keyInfo = new KeyInfo();
keyInfo.AddClau se(new RSAKeyValue((RS A)Key));
signedXml.KeyIn fo = keyInfo;

// Compute the signature.
signedXml.Compu teSignature();

// Get the XML representation of the signature and save
// it to an XmlElement object.
XmlElement xmlDigitalSigna ture = signedXml.GetXm l();

// Append the element to the XML document.
doc.DocumentEle ment.AppendChil d(doc.ImportNod e(xmlDigitalSig nature,
true));
if (doc.FirstChild is XmlDeclaration)
{
doc.RemoveChild (doc.FirstChild );
}

// Save the signed XML document to a file specified
// using the passed string.
XmlTextWriter xmltw = new XmlTextWriter(S ignedFileName, new
UTF8Encoding(fa lse));
doc.WriteTo(xml tw);
xmltw.Close();
}

Nov 12 '05 #2
Unfortunately this is not a solution. The signature can not be verified
afterwards.
I found a lot of questions similar to my question in the Internet. But
always
without a meaningful answer.

May be somebody from Microsoft can please answer this question. Even
an "currently impossible" would be helpfull. I already invested several days
into this topic.

"S. Baumann" <no*****@xyz.co m> wrote in message
news:ea******** ******@TK2MSFTN GP09.phx.gbl...
I solved it myself

Void ChangePrefix (XmlNode ^ pNode)
{
if ( !pNode)
return;

do
{
pNode->Prefix = "ds";

ChangePrefix (pNode->FirstChild);
}
while ( pNode = pNode->NextSibling );
}
"S. Baumann" <no*****@xyz.co m> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Hello,

I use a code very similar to that found in the MSDN sample attached to
the class XmlDsigEnvelope dSignatureTrans form (code attached below).
The code works fine and produces somethink like
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
<Canonicalizati onMethod
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 ds prefix:

<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:SignedInf o>
....
</ds:Signature>

How can I achive this?

Any help would be greatly appreciated
Code that I use:

// Sign an XML file and save the signature in a new file.
public static void SignXmlFile(str ing FileName, string SignedFileName,
RSA Key)
{
// Create a new XML document.
XmlDocument doc = new XmlDocument();

// Format the document to ignore white spaces.
doc.PreserveWhi tespace = false;

// Load the passed XML file using it's name.
doc.Load(new XmlTextReader(F ileName));

// Create a SignedXml object.
SignedXml signedXml = new SignedXml(doc);

// Add the key to the SignedXml document.
signedXml.Signi ngKey = Key;

// Create a reference to be signed.
Reference reference = new Reference();
reference.Uri = "";

// Add a transformation to the reference.
Transform trns = new XmlDsigC14NTran sform();
reference.AddTr ansform(trns);

// Add an enveloped transformation to the reference.
XmlDsigEnvelope dSignatureTrans form env = new
XmlDsigEnvelope dSignatureTrans form();
reference.AddTr ansform(env);

// Add the reference to the SignedXml object.
signedXml.AddRe ference(referen ce);
// Add an RSAKeyValue KeyInfo (optional; helps recipient find key
to validate).
KeyInfo keyInfo = new KeyInfo();
keyInfo.AddClau se(new RSAKeyValue((RS A)Key));
signedXml.KeyIn fo = keyInfo;

// Compute the signature.
signedXml.Compu teSignature();

// Get the XML representation of the signature and save
// it to an XmlElement object.
XmlElement xmlDigitalSigna ture = signedXml.GetXm l();

// Append the element to the XML document.

doc.DocumentEle ment.AppendChil d(doc.ImportNod e(xmlDigitalSig nature,
true));
if (doc.FirstChild is XmlDeclaration)
{
doc.RemoveChild (doc.FirstChild );
}

// Save the signed XML document to a file specified
// using the passed string.
XmlTextWriter xmltw = new XmlTextWriter(S ignedFileName, new
UTF8Encoding(fa lse));
doc.WriteTo(xml tw);
xmltw.Close();
}


Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1161
by: Kim H Madsen | last post by:
I have created a .Net Service that is sending mails using SMTP Server/Exchange Server how do i put in a Digital Signature so the reciver is 100% sure that the mail i from the owner of Server where the Service is running ? It should worke something lige Outlook does it you type in your secret password and Outlook together with the code create a...
1
4986
by: Arkady Frenkel | last post by:
Hi! I try to make digital signature of the blob and check it , but on check ( signature created and seems OK ) I catch exception : "An XmlDocument context is required to resolve the Reference Uri ." If instead of line reference.Uri = ""; If I put here some correct Uri - like
0
1565
by: CLarkou | last post by:
I bought a digital signature for my MSaccess application in Office 2003. I select TOOLS\Digital Signatures in Visual Basic Editor and I am not able to see my digital signature in the available ones. No BROWSE button available. Is there any directory I should copy it into ?
0
454
by: - | last post by:
I use a code very similar to that found in the MSDN sample attached to the class XmlDsigEnvelopedSignatureTransform. The code works fine and produces somethink like <Signature xmlns="http://www.w3.org/2000/09/xmldsig#"> <SignedInfo> <CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" /> ................
1
3642
by: Marco Moioli | last post by:
Hi, I have a problem with a X509 digital signature. I want to sign a Word 2003 document saved in .xml format. the problem is that after the signature, Word 2003 don't want to open the document. If I apply a standard W3C signature to an Xml file wrote in Word 2003 I obtain: <?mso-application progid="Word.Document"?> <w:wordDocument
0
2581
by: Geagleeye | last post by:
Hi everyone. I have some vba code to generate a pdf document through word, and add also digital signature. My problem is : how can i change the way the signature layout, it always show the same standard signature image look. I have tryed to change my signature field whit my own logo and so on in acrobat, and named it as signtaure 2,...
2
21524
by: scottpet | last post by:
Hi, I want to add a namespace prefix to the root node of an object I am serializing to XML. I have been reading though this article: http://msdn2.microsoft.com/en-gb/library/system.xml.serialization.xmlnamespacedeclarationsattribute.aspx I get namespace prefixes in the document, but not on the root node. Specifically, the serializer...
3
2790
by: itcoll | last post by:
i have wriiten java code for client server communication - the client sends a digital signature and the server verifies it using the public key .I have sent the signature as a string from the client to server.although the verification comes as true most of the times , some times it comes as "false" .i dont know why it comes that way . so my...
3
3165
by: tmoloy | last post by:
I am using RFID tags to store some data which will then be read by a 3rd party. I need to include a digital signature (or some variation) along with the data so that the 3rd party can verify the authenticity of the tag. Straightforward enough. But the problem is that I am constrained by the RFID tag's 32-byte memory array. My application is...
0
7532
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7730
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7492
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7823
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
3510
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3491
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1957
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1069
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
777
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.