Re: Compute XML Signature on external Xml document
From: Ivan Medvedev [MS] (ivanmed_at_online.microsoft.com)
Date: 05/21/03
- Next message: Wallace B. McClure: "Re: ODBC access within a Windows Service"
- Previous message: Ferruccio Barletta: "Re: Authenticate in SAM database..."
- In reply to: J-P Meunier: "Compute XML Signature on external Xml document"
- Next in thread: J-P Meunier: "Re: Compute XML Signature on external Xml document"
- Reply: J-P Meunier: "Re: Compute XML Signature on external Xml document"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Wed, 21 May 2003 09:56:37 -0700
J-P -
you will need to use an EnvelopedSignatureTransform. Here is approximately
how you would do this:
------------------------- sign --------------------------
XmlDocument doc = ... // your enveloping document
SignedXml signedXml = new SignedXml(doc);
signedXml.SigningKey = ... // your signing key
Reference reference = new Reference();
reference.Uri = "";
XmlDsigEnvelopedSignatureTransform env = new
XmlDsigEnvelopedSignatureTransform();
reference.AddTransform(env);
signedXml.AddReference(reference);
... // add key info if neccessary
signedXml.ComputeSignature();
// now insert the signature into the doc
XmlElement xmlDigitalSignature = signedXml.GetXml();
XmlTextWriter xmltw = new XmlTextWriter( _name_ , new
UTF8Encoding(false));
doc.DocumentElement.AppendChild(doc.ImportNode(xmlDigitalSignature,
true)); // insert the signature into the document
if (doc.FirstChild is XmlDeclaration) doc.RemoveChild(doc.FirstChild);
doc.WriteTo(xmltw);
xmltw.Close();
------------------------ verify ---------------------------
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.PreserveWhitespace = true;
xmlDocument.Load(_name_);
SignedXml signedXml = new SignedXml(xmlDocument);
XmlNodeList nodeList =
xmlDocument.GetElementsByTagName("Signature");
signedXml.LoadXml((XmlElement)nodeList[0]);
return signedXml.CheckSignature();
-----------------------------------------------------------
Hope this helps.
--Ivan
This posting is provided "AS IS" with no warranties, and confers no rights.
"J-P Meunier" <fuimens@yahoo.fr> wrote in message
news:eGEI053HDHA.2176@TK2MSFTNGP10.phx.gbl...
> Hi all,
>
> I need to make an Xml Signature
(System.Security.Cryptography.Xml.SignedXml)
> of an XmlDocument and then to include the signature into that XmlDocument.
>
> Example:
> <XmlSign>
> <Identity id="ToBeSigned">
> <Name>myName</Name>
> <Surname>mySignature</Surname>
> </Identity>
> <IdentitySignature>
> *SignedXml*
> </IdentitySignature>
> <XmlSign>
>
> The solution would be to create a SignedXml object and insert it
> <IdentitySignature>, to set the correct references and then to compute
the
> signature. But I can't to that because the XML element of SignedXml can't
be
> accessed before computing the signature ...
>
> So how can I solve that problem?
> Any comment would be appreciated,
>
> Thanks
>
> J-P
>
>
- Next message: Wallace B. McClure: "Re: ODBC access within a Windows Service"
- Previous message: Ferruccio Barletta: "Re: Authenticate in SAM database..."
- In reply to: J-P Meunier: "Compute XML Signature on external Xml document"
- Next in thread: J-P Meunier: "Re: Compute XML Signature on external Xml document"
- Reply: J-P Meunier: "Re: Compute XML Signature on external Xml document"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|