Geeks With Blogs
Pradeep Loganathan Distributed

using System.IO;

using System.Xml;

using System.Security;

using System.Security.Cryptography;

using System.Security.Cryptography.Xml;

namespace XMLDIGSIG

{

class Program

{

static void Main(string[] args)

{

SignXML();

ValidateXML();

Console.ReadKey();

}

private static void SignXML()

{

XmlDocument doc = new XmlDocument();

doc.Load("xmlfile1.xml");

SignedXml sx = new SignedXml(doc);

RSA Key = new RSACryptoServiceProvider();

sx.KeyInfo = new KeyInfo();

sx.KeyInfo.AddClause(new RSAKeyValue(Key));

sx.SigningKey = Key;

Reference refer = new Reference("");

refer.AddTransform(new XmlDsigEnvelopedSignatureTransform());

sx.AddReference(refer);

sx.ComputeSignature();

doc.DocumentElement.AppendChild(sx.GetXml());

doc.Save("Signedxml.xml");

}

private static void ValidateXML()

{

XmlDocument doc = new XmlDocument();

doc.Load("Signedxml.xml");

SignedXml verify = new SignedXml(doc);

verify.LoadXml((XmlElement)(doc.GetElementsByTagName("Signature")[0]));

if( verify.CheckSignature())

Console.WriteLine("Signature verified --- Match");

else

Console.WriteLine("Signature verified --- No Match");

}

}

}

Posted on Thursday, August 3, 2006 5:23 AM WS-Security | Back to top

Copyright © Pradeep Loganathan | Powered by: GeeksWithBlogs.net