Re: SignedXml.CheckSignature fails
From: Ivan Medvedev [MS] (ivanmed_at_online.microsoft.com)
Date: 05/15/03
- Next message: Alex: "Re: How to determine if currently logged in user belongs to a local user group?"
- Previous message: Joe Kaplan: "Re: How to determine if currently logged in user belongs to a local user group?"
- In reply to: J-P Meunier: "Re: SignedXml.CheckSignature fails"
- Next in thread: J-P Meunier: "Re: SignedXml.CheckSignature fails"
- Reply: J-P Meunier: "Re: SignedXml.CheckSignature fails"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Thu, 15 May 2003 09:15:46 -0700
J-P -
In this case you can not verify the signature with the same SignedXml
object - its context needs to be set to the enveloping document, and it is
only possible when the object is constructed.
Here is how to verify your signature (put right after the call to
ComputeSignature):
------------------ cut ----------------
XmlDocument doc2 = new XmlDocument();
doc2.PreserveWhitespace = true;
doc2.LoadXml(signedXml.GetXml().OuterXml);
signedXml = new SignedXml(doc2);
XmlNodeList nodeList = doc2.GetElementsByTagName("Signature");
signedXml.LoadXml((XmlElement)nodeList[0]);
Console.WriteLine(signedXml.CheckSignature());
------------------ cut ----------------
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:uhsimZrGDHA.2172@TK2MSFTNGP12.phx.gbl...
> Ivan,
>
> I call the two functions (compute and check) in the same routine:
>
> ...
> SignedXml signedXml = new SignedXml();
>
> signedXml.SigningKey = rsaKeyPair; //already generated key
>
> XmlDocument xdMainFile = new XmlDocument(); //file to sign
> XmlNode xnMainFile = xdMainFile.CreateNode(XmlNodeType.Element, "",
> "MainFile", "");
> xnMainFile.InnerText = strMainFileContent; //base64 encoded string
> xdMainFile.AppendChild(xnMainFile);
>
> DataObject dataObject = new DataObject();
> dataObject.Data = xdMainFile.ChildNodes;
> dataObject.Id = "MainFile";
> signedXml.AddObject(dataObject);
>
> Reference reference = new Reference();
> reference.Uri = "#MainFile";
> signedXml.AddReference(reference);
>
> KeyInfo keyInfo = new KeyInfo();
> keyInfo.AddClause(new RSAKeyValue(rsaKeyPair));
> signedXml.KeyInfo = keyInfo;
>
> signedXml.ComputeSignature(); // produces the XML posted in the first
> message
> signedXml.CheckSignature(); // fails
> ...
>
> Where am I supposed to do PreserveWhitespace = true ?
>
> Thanks,
>
> J-P
>
> "Ivan Medvedev [MS]" <ivanmed@online.microsoft.com> a écrit dans le
message
> de news: uoacVVjGDHA.2200@TK2MSFTNGP11.phx.gbl...
> > J-P -
> > have you done XmlDocument.PreserveWhitespace=true in both sign and
verify
> > routines?
> > Thanks,
> > --Ivan
> > This posting is provided "AS IS" with no warranties, and confers no
> rights.
> >
> >
> > "J-P Meunier" <fuimens@yahoo.fr> wrote in message
> > news:OL5c6oiGDHA.1660@TK2MSFTNGP10.phx.gbl...
> > > Hi all,
> > >
> > > I can't verify the XML Signature I just have generated (in the same
> > > program). The function CheckSignature (called immedialtely after
> > > ComputeSignature) throws a "Incorrect Reference" Error.
> > >
> > > Here is the SignedXml object I get when I call ComputeSignature :
> > >
> > > <SignedInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
> > > <CanonicalizationMethod
> > > Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
> > > <SignatureMethod
> > Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"
> > > />
> > > <Reference URI="#MainFile">
> > > <DigestMethod
Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"
> > />
> > > <DigestValue>w7o1zJRNO4MkRyJ2dFKAdc93t2w=</DigestValue>
> > > </Reference>
> > > </SignedInfo>
> > > <SignatureValue
xmlns="http://www.w3.org/2000/09/xmldsig#">cMo1VIuso0qH
> > ...
> > > to end of signature</SignatureValue>
> > > <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
> > > <KeyValue xmlns="http://www.w3.org/2000/09/xmldsig#">
> > > <RSAKeyValue>
> > > <Modulus>vuUqF6 ... to end of modulus</Modulus>
> > > <Exponent>AQAB</Exponent>
> > > </RSAKeyValue>
> > > </KeyValue>
> > > </KeyInfo>
> > > <Object Id="MainFile" xmlns="http://www.w3.org/2000/09/xmldsig#">
> > > <MainFile xmlns="">UmV0dXJuLV ... to end of
mainfile</MainFile>
> > > </Object>
> > >
> > > Question : What is wrong with this Xml ?
> > >
> > > Thanks
> > >
> > > J-P
> > >
> > >
> >
> >
>
>
- Next message: Alex: "Re: How to determine if currently logged in user belongs to a local user group?"
- Previous message: Joe Kaplan: "Re: How to determine if currently logged in user belongs to a local user group?"
- In reply to: J-P Meunier: "Re: SignedXml.CheckSignature fails"
- Next in thread: J-P Meunier: "Re: SignedXml.CheckSignature fails"
- Reply: J-P Meunier: "Re: SignedXml.CheckSignature fails"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|