all groups > dotnet xml > september 2005 >
You're in the

dotnet xml

group:

Digital signature of the blob?


Digital signature of the blob? Arkady Frenkel
9/7/2005 12:00:00 AM
dotnet xml:
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

reference.Uri = http://www.microsoft.com

No exception on CheckSignature() happen and resut is true

Is it possible to do with blob and without URI?

I tried to set : reference.Uri = "Body" but catched exception too

Here the code ( C# ) :

string str = "<Body>aaaaaaaaaaaaaaaaaa</Body>" ; // blob I want to sign

XmlTextReader r = new XmlTextReader(new StringReader(str));

XmlDocument document = new XmlDocument();

document.Load(r);

SignedXml signedXml = new SignedXml(document);

RSA key = RSA.Create();

signedXml.SigningKey = key;


Reference reference = new Reference();

reference.Uri = ""; // If I put here some correct Uri - like
"http://www.microsoft.com"

signedXml.AddReference(reference);

KeyInfo keyInfo = new KeyInfo();

keyInfo.AddClause(new RSAKeyValue(key));

signedXml.KeyInfo = keyInfo;

signedXml.ComputeSignature();

XmlElement xmlDigitalSignature = signedXml.GetXml();

StringWriter sw = new StringWriter();

XmlTextWriter xmltw = new XmlTextWriter(sw);

xmlDigitalSignature.WriteTo(xmltw);

string s = sw.ToString();

xmltw.Close();

XmlTextReader rr = new XmlTextReader(new StringReader(s));

XmlDocument xmlDocument = new XmlDocument();

xmlDocument.Load(rr);


signedXml = new SignedXml();

XmlNodeList nodeList = xmlDocument.GetElementsByTagName("Signature");

signedXml.LoadXml((XmlElement)nodeList[0]);

// Check the signature and return the result.

try

{

b = signedXml.CheckSignature();

}

catch(CryptographicException e)

{

Console.WriteLine(e.Message);

}

TIA
Arkady

Re: Digital signature of the blob? Arkady Frenkel
9/8/2005 11:52:32 AM
Never mind , I did it : URI have to include #XXX ( Id ) so object ( "Body"
in my case ) have to have "Id=XXX" and xml for Check have to include both
( original xml text and signature ) to be checked corrrectly
Arkady

[quoted text, click to view]

AddThis Social Bookmark Button