SlideShare ist ein Scribd-Unternehmen logo
1 von 6
Downloaden Sie, um offline zu lesen
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
1. Encryption Class
using
using
using
using
using
using
using
using
using
using
using
using

System;
System.Data;
System.Configuration;
System.Web;
System.Web.Security;
System.Web.UI;
System.Web.UI.WebControls;
System.Web.UI.WebControls.WebParts;
System.Web.UI.HtmlControls;
System.Xml;
System.Security.Cryptography;
System.Security.Cryptography.Xml;

/// <summary>
/// encryption: encrypts xml data with RSA algorithm, reference:
http://msdn2.microsoft.com/en-us/library/ms229749(VS.80).aspx
/// </summary>
public class encryption
{
public void Encrypt(XmlDocument Doc, string ElementToEncrypt, RSA Alg,
string KeyName)
{
// Check the arguments.
if (Doc == null)
throw new ArgumentNullException("Doc");
if (ElementToEncrypt == null)
throw new ArgumentNullException("ElementToEncrypt");
if (Alg == null)
throw new ArgumentNullException("Alg");
if (KeyName == null)
throw new ArgumentNullException("KeyName");

XmlElement xmlElemt = Doc.GetElementsByTagName(ElementToEncrypt)[0]
as XmlElement;
EncryptedXml xmlEnc = new EncryptedXml(Doc);
xmlEnc.AddKeyNameMapping(KeyName,Alg);
EncryptedData encXml = xmlEnc.Encrypt(xmlElemt,KeyName);
EncryptedXml.ReplaceElement(xmlElemt, encXml, false);
}

}

2
2. Decryption Class
using
using
using
using
using
using
using
using
using
using
using
using

System;
System.Data;
System.Configuration;
System.Web;
System.Web.Security;
System.Web.UI;
System.Web.UI.WebControls;
System.Web.UI.WebControls.WebParts;
System.Web.UI.HtmlControls;
System.Xml;
System.Security.Cryptography;
System.Security.Cryptography.Xml;

/// <summary>
/// decryption: decrypts xml data with RSA algorithm, reference:
http://msdn2.microsoft.com/en-us/library/ms229749(VS.80).aspx
/// </summary>
public class decryption
{

public void Decrypt(XmlDocument Doc, RSA Alg, string KeyName)
{
// Check the arguments.
if (Doc == null)
throw new ArgumentNullException("Doc");
if (Alg == null)
throw new ArgumentNullException("Alg");
if (KeyName == null)
throw new ArgumentNullException("KeyName");
// Create a new EncryptedXml object.
EncryptedXml exml = new EncryptedXml(Doc);

// Add a key-name mapping.
// This method can only decrypt documents
// that present the specified key name.
exml.AddKeyNameMapping(KeyName, Alg);
// Decrypt the element.
exml.DecryptDocument();
}

}

3
3. Signature Class
using
using
using
using
using
using
using
using
using
using
using
using

System;
System.Data;
System.Configuration;
System.Web;
System.Web.Security;
System.Web.UI;
System.Web.UI.WebControls;
System.Web.UI.WebControls.WebParts;
System.Web.UI.HtmlControls;
System.Xml;
System.Security.Cryptography;
System.Security.Cryptography.Xml;

/// <summary>
/// signature class: Signs multiple Xml according to the reference.Uri
/// </summary>
public class signature
{
public void SignXml(XmlDocument Doc, RSA Key, int c)
{
// Check arguments.
if (Doc == null)
throw new ArgumentException("Doc");
if (Key == null)
throw new ArgumentException("Key");
// Create a SignedXml object.
SignedXml signedXml = new SignedXml(Doc);
// Add the key to the SignedXml document.
signedXml.SigningKey = Key;
// Create a reference to be signed.<<Create a Reference object that
describes what to sign.>>
Reference reference = new Reference();
if (c == 1)
{
reference.Uri = "#c";
}
else if (c == 2)
{
reference.Uri = "#s";
}
else if (c == 3)
{
}

reference.Uri = "#m";

4
// 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
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

Weitere ähnliche Inhalte

Ähnlich wie Appendix

Step4 managementsendsorderw
Step4 managementsendsorderwStep4 managementsendsorderw
Step4 managementsendsorderw
Hüseyin Çakır
 
Developing your first application using FIWARE
Developing your first application using FIWAREDeveloping your first application using FIWARE
Developing your first application using FIWARE
FIWARE
 

Ähnlich wie Appendix (20)

Conclusion
ConclusionConclusion
Conclusion
 
Tigerstripe @ Eclipse Summit 08
Tigerstripe @ Eclipse Summit 08Tigerstripe @ Eclipse Summit 08
Tigerstripe @ Eclipse Summit 08
 
Step4 managementsendsorderw
Step4 managementsendsorderwStep4 managementsendsorderw
Step4 managementsendsorderw
 
7\9 SSIS 2008R2_Training - Script Task
7\9 SSIS 2008R2_Training - Script Task7\9 SSIS 2008R2_Training - Script Task
7\9 SSIS 2008R2_Training - Script Task
 
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
Unit 1 - TypeScript & Introduction to Angular CLI.pptxUnit 1 - TypeScript & Introduction to Angular CLI.pptx
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
 
Building 12-factor Cloud Native Microservices
Building 12-factor Cloud Native MicroservicesBuilding 12-factor Cloud Native Microservices
Building 12-factor Cloud Native Microservices
 
Live Coding 12 Factor App
Live Coding 12 Factor AppLive Coding 12 Factor App
Live Coding 12 Factor App
 
Microsoft Graph community call-October 2018
Microsoft Graph community call-October 2018Microsoft Graph community call-October 2018
Microsoft Graph community call-October 2018
 
Java EE Connector Architecture 1.6 (JSR 322) Technology
Java EE Connector Architecture 1.6 (JSR 322) TechnologyJava EE Connector Architecture 1.6 (JSR 322) Technology
Java EE Connector Architecture 1.6 (JSR 322) Technology
 
Ian 2014.10.24 weekly report
Ian 2014.10.24 weekly reportIan 2014.10.24 weekly report
Ian 2014.10.24 weekly report
 
Using Splunk or ELK for Auditing AWS/GCP/Azure Security posture
Using Splunk or ELK for Auditing AWS/GCP/Azure Security postureUsing Splunk or ELK for Auditing AWS/GCP/Azure Security posture
Using Splunk or ELK for Auditing AWS/GCP/Azure Security posture
 
Using Splunk/ELK for auditing AWS/GCP/Azure security posture
Using Splunk/ELK for auditing AWS/GCP/Azure security postureUsing Splunk/ELK for auditing AWS/GCP/Azure security posture
Using Splunk/ELK for auditing AWS/GCP/Azure security posture
 
Advanced Web Development
Advanced Web DevelopmentAdvanced Web Development
Advanced Web Development
 
Microsoft Graph community call May, 2018
Microsoft Graph community call May, 2018Microsoft Graph community call May, 2018
Microsoft Graph community call May, 2018
 
Developing your first application using FIWARE
Developing your first application using FIWAREDeveloping your first application using FIWARE
Developing your first application using FIWARE
 
Introduction to Aspect Oriented Software Development
Introduction to Aspect Oriented Software DevelopmentIntroduction to Aspect Oriented Software Development
Introduction to Aspect Oriented Software Development
 
Saving Time And Effort With QuickBase Api - Sergio Haro
Saving Time And Effort With QuickBase Api - Sergio HaroSaving Time And Effort With QuickBase Api - Sergio Haro
Saving Time And Effort With QuickBase Api - Sergio Haro
 
Interoperable Component Patterns
Interoperable Component PatternsInteroperable Component Patterns
Interoperable Component Patterns
 
Complex Sites with Silex
Complex Sites with SilexComplex Sites with Silex
Complex Sites with Silex
 
Key features of rails 5.2 (2)
Key features of rails 5.2 (2)Key features of rails 5.2 (2)
Key features of rails 5.2 (2)
 

Mehr von Hüseyin Çakır

Mehr von Hüseyin Çakır (8)

Step3sales deptsendsmanagement
Step3sales deptsendsmanagementStep3sales deptsendsmanagement
Step3sales deptsendsmanagement
 
Step2sales deptsendswarehouse
Step2sales deptsendswarehouseStep2sales deptsendswarehouse
Step2sales deptsendswarehouse
 
Step1customer sendsorder
Step1customer sendsorderStep1customer sendsorder
Step1customer sendsorder
 
Scenario
ScenarioScenario
Scenario
 
Project plan
Project planProject plan
Project plan
 
Introduction
IntroductionIntroduction
Introduction
 
Table ofcontents
Table ofcontentsTable ofcontents
Table ofcontents
 
Cover
CoverCover
Cover
 

Kürzlich hochgeladen

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Kürzlich hochgeladen (20)

Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 

Appendix

  • 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
  • 2. 1. Encryption Class using using using using using using using using using using using using System; System.Data; System.Configuration; System.Web; System.Web.Security; System.Web.UI; System.Web.UI.WebControls; System.Web.UI.WebControls.WebParts; System.Web.UI.HtmlControls; System.Xml; System.Security.Cryptography; System.Security.Cryptography.Xml; /// <summary> /// encryption: encrypts xml data with RSA algorithm, reference: http://msdn2.microsoft.com/en-us/library/ms229749(VS.80).aspx /// </summary> public class encryption { public void Encrypt(XmlDocument Doc, string ElementToEncrypt, RSA Alg, string KeyName) { // Check the arguments. if (Doc == null) throw new ArgumentNullException("Doc"); if (ElementToEncrypt == null) throw new ArgumentNullException("ElementToEncrypt"); if (Alg == null) throw new ArgumentNullException("Alg"); if (KeyName == null) throw new ArgumentNullException("KeyName"); XmlElement xmlElemt = Doc.GetElementsByTagName(ElementToEncrypt)[0] as XmlElement; EncryptedXml xmlEnc = new EncryptedXml(Doc); xmlEnc.AddKeyNameMapping(KeyName,Alg); EncryptedData encXml = xmlEnc.Encrypt(xmlElemt,KeyName); EncryptedXml.ReplaceElement(xmlElemt, encXml, false); } } 2
  • 3. 2. Decryption Class using using using using using using using using using using using using System; System.Data; System.Configuration; System.Web; System.Web.Security; System.Web.UI; System.Web.UI.WebControls; System.Web.UI.WebControls.WebParts; System.Web.UI.HtmlControls; System.Xml; System.Security.Cryptography; System.Security.Cryptography.Xml; /// <summary> /// decryption: decrypts xml data with RSA algorithm, reference: http://msdn2.microsoft.com/en-us/library/ms229749(VS.80).aspx /// </summary> public class decryption { public void Decrypt(XmlDocument Doc, RSA Alg, string KeyName) { // Check the arguments. if (Doc == null) throw new ArgumentNullException("Doc"); if (Alg == null) throw new ArgumentNullException("Alg"); if (KeyName == null) throw new ArgumentNullException("KeyName"); // Create a new EncryptedXml object. EncryptedXml exml = new EncryptedXml(Doc); // Add a key-name mapping. // This method can only decrypt documents // that present the specified key name. exml.AddKeyNameMapping(KeyName, Alg); // Decrypt the element. exml.DecryptDocument(); } } 3
  • 4. 3. Signature Class using using using using using using using using using using using using System; System.Data; System.Configuration; System.Web; System.Web.Security; System.Web.UI; System.Web.UI.WebControls; System.Web.UI.WebControls.WebParts; System.Web.UI.HtmlControls; System.Xml; System.Security.Cryptography; System.Security.Cryptography.Xml; /// <summary> /// signature class: Signs multiple Xml according to the reference.Uri /// </summary> public class signature { public void SignXml(XmlDocument Doc, RSA Key, int c) { // Check arguments. if (Doc == null) throw new ArgumentException("Doc"); if (Key == null) throw new ArgumentException("Key"); // Create a SignedXml object. SignedXml signedXml = new SignedXml(Doc); // Add the key to the SignedXml document. signedXml.SigningKey = Key; // Create a reference to be signed.<<Create a Reference object that describes what to sign.>> Reference reference = new Reference(); if (c == 1) { reference.Uri = "#c"; } else if (c == 2) { reference.Uri = "#s"; } else if (c == 3) { } reference.Uri = "#m"; 4
  • 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