Help convert C# code relating to signing xml

 Hi

To summarize:

In VC 2.3 for VS, we need to digitally sign portions of an XML document in SOAP envelope.  We are using classes in System.Security.Cryptography.Xml, in particular the class SignedXml

We are having trouble signing xml when we add a Reference based on an Id attribute.  We are getting "Malformed Reference Element" exception when ComputeSignature is invoked.

After much searhing on the internet I made have found the answer in stackoverflow, but I need to convert C# code below:

 

public class SignedXmlWithId : SignedXml
{
public SignedXmlWithId(XmlDocument xml) : base(xml)
{
}

public SignedXmlWithId(XmlElement xmlElement)
: base(xmlElement)
{
}

public override XmlElement GetIdElement(XmlDocument doc, string id)
{
// check to see if it's a standard ID reference
XmlElement idElem = base.GetIdElement(doc, id);

if (idElem == null)
{
XmlNamespaceManager nsManager = new XmlNamespaceManager(doc.NameTable);
nsManager.AddNamespace("wsu", "docs.oasis-open.org/.../oasis-200401-wss-wssecurity-utility-1.0.xsd");

idElem = doc.SelectSingleNode("//*[@wsu:Id=\"" id "\"]", nsManager) as XmlElement;
}

return idElem;
}
}

 

Converting the above code may be the answer, otherwise I may need more help.

Many thanks

Brendan

Parents Reply Children
No Data