1. SENIOR PROJECT 2007-2008
(Appendix of the ekoSign project)
Appendix
Project team members
Hüseyin Çakır, Mehmet Mesut Özışık, Yılmaz Kaya
Abstract:This paper includes the codes of the some classes used in the project.
Keywords:Encryption class, Decryption class, Signature class, verfySignature class.
http://groups.google.com/group/digitalsignature
digitalsignature@googlegroups.com
PRINT DATE: 05/06/08
1
5. // Add an enveloped transformation to the reference.
XmlDsigEnvelopedSignatureTransform env = new
XmlDsigEnvelopedSignatureTransform();
reference.AddTransform(env);
// Add the reference to the SignedXml object.
signedXml.AddReference(reference);
// Compute the signature.
signedXml.ComputeSignature();
// Get the XML representation of the signature and save
// it to an XmlElement object.
XmlElement xmlDigitalSignature = signedXml.GetXml();
true));
// Append the element to the XML document.
Doc.DocumentElement.AppendChild(Doc.ImportNode(xmlDigitalSignature,
}
}
5
6. 4. verifySignature Class
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.Security.Cryptography;
using System.Security.Cryptography.Xml;
/// <summary>
/// verifySignature class: Verifies multiple Xml according to the reference.Uri
/// </summary>
public class verifySignature
{
// Verify the signature of an XML file against an asymmetric
// algorithm and return the result.
public Boolean VerifyXml(XmlDocument Doc, RSA Key,int i)
{
// Check arguments.
if (Doc == null)
throw new ArgumentException("Doc");
if (Key == null)
throw new ArgumentException("Key");
// Create a new SignedXml object and pass it
// the XML document class.
SignedXml signedXml = new SignedXml(Doc);
// Find the "Signature" node and create a new
// XmlNodeList object.
XmlNodeList nodeList = Doc.GetElementsByTagName("Signature");
// Throw an exception if no signature was found.
if (nodeList.Count <= 0)
{
throw new CryptographicException("Verification failed: No
Signature was found in the document.");
}
else{
// Load the first <signature> node.
signedXml.LoadXml((XmlElement)nodeList[i]);
// Check the signature and return the result.
return signedXml.CheckSignature(Key);
}
}
}
6