473,394 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

SignedXml question

Given the following, how do I get the plain xml without the security
elements (i.e. the original xml before the security was added) in the
VerifyXML() method. TIA.

using System;
using System.Security.Cryptography;
using System.Security.Cryptography.Xml;
using System.Xml;
using System.IO;

namespace SocketServers.NetFile
{
/// <summary>
/// Summary description for SecXML.
/// </summary>
public class SecXML
{
private RSA key;

public SecXML()
{
}

public string CreateXML(string xmlString)
{
XmlDocument doc = new XmlDocument();
//doc.PreserveWhitespace = true;
doc.LoadXml(xmlString);
SignedXml sig = new SignedXml(doc);

key = new RSACryptoServiceProvider();
//string privateKey = key.ToXmlString(true);
//string publicKey = key.ToXmlString(false);
//Console.WriteLine("Private Key:" + privateKey);
//Console.WriteLine("Public Key:" + publicKey);

//After this, save the public and private keys using a StreamWriter, and
re-use them in code like so:
//RSACryptoServiceProvider csp = new RSACryptoServiceProvider();
//csp.FromXmlString(xmlkey); // where xmlKey is the saved private or
public key xml from the step above
sig.SigningKey = key;

Reference reff = new Reference("");
reff.AddTransform(new XmlDsigEnvelopedSignatureTransform());
sig.AddReference(reff);

sig.ComputeSignature();
doc.DocumentElement.AppendChild(sig.GetXml());
StringWriter sw = new StringWriter();
doc.Save(sw);
return sw.ToString();
}

public bool VerifyXML(string xml)
{
XmlDocument doc = new XmlDocument();
//doc.PreserveWhitespace = true;
doc.LoadXml(xml);

XmlNamespaceManager nsm = new XmlNamespaceManager(new NameTable());
nsm.AddNamespace("dsig", SignedXml.XmlDsigNamespaceUrl);
XmlElement sigElement =
(XmlElement)doc.SelectSingleNode("//dsig:Signature", nsm);

SignedXml sig = new SignedXml(doc);
sig.LoadXml(sigElement);
Console.WriteLine("Outer:\n"+doc.OuterXml);
if ( sig.CheckSignature(key))
return true;
return false;
}
}
}

--
William Stacey, MVP
Nov 16 '05 #1
2 2566
Hi William,

We have reviewed this issue and are currently researching on it. We will
update you ASAP. Thanks for your patience!

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #2
Hi William,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to get the original Xml text
from the signed xml. If there is any misunderstanding, please feel free to
let me know.

As far as I can see, the CreateXml method only adds a <Signature> element
under the root element with doc.DocumentElement.AppendChild(sig.GetXml());.
I think what we need to do is to remove that element. So, we can load that
string to an XmlDocument and remove that node using RemoveChild method. HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #3

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

Similar topics

5
by: Raghu | last post by:
I am using SignedXml class to sign and verify soap xml documents. We are not using WSE at this point. When I sign a soap document and send it to my trading partner, they can verify the document...
7
by: Guangxi Wu | last post by:
Hi all, Happy New Year. I am using SignedXML and an X509 certificate to digitally sign a SOAP message body and put the signature in the SOAP header for a B2B business application. Can you...
0
by: pak76 | last post by:
Class SignedXml is used to produce/verify signature over XML document. One of its methods, function GetIdElement, is used to select Xml elements for signature and verification and consist following...
0
by: ChrisA | last post by:
I'm using Michael Gallants DecodeCertKey example to get the public key from an X509 certificate. I then create an RSAServiceProvider and try to use it to CheckSignature() on the signed XML file....
2
by: Nikhil | last post by:
When I try to used the CheckSignature Method of SignedXML I get the following error. "Unknown transform has been encountered. at System.Security.Cryptography.Xml.Reference.LoadXml(XmlElement...
4
by: Karol | last post by:
Hello, I'm trying to create signed XML document with SignedXml class. As a SigningKey I'd like to use key pair obtained from user certificate stored in current user certificate store. I'm using...
2
by: Rune Nergard | last post by:
I have tried to use the System.Security.Cryptography.Xml.SignedXml class to sign an Xml message with Xml-DSIG and using an Enveloped signature type and the sha1RSA algorithm. Everything works fine...
1
by: Peter Ravnholt | last post by:
Hello all, It seems that digitally signing XML documents using the SignedXml class has a bug - or at least a behavior I cannot explain. The problem occurs when I sign XML documents containing...
0
by: Iguana | last post by:
Hi! Im creating project in c# .net2.0, to sign and verify documens us xmldsig format. My problem is how to use prefix "ds" instead of: xmlns="http://www.w3.org/2000/09/xmldsig#" in SignedInfo,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.