How To: Create Digital Signature

This is a discussion on "How To: Create Digital Signature" within the ASP.NET Forum section. This forum, and the thread "How To: Create Digital Signature are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > ASP.NET Forum

Notices


Reply
 
LinkBack (2) Thread Tools
  2 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old Nov 2nd, 2006, 12:13
New Member
Join Date: Nov 2006
Location: New Delhi
Age: 30
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
How To: Create Digital Signature

I created a Digital Certificate and installed into the Certificate Store of the Local Machine. On .aspx page, the certificate is read from the store and the Digital Certificate is to be created with the Payload Information.
Below is the code written for the purpose.
postDocument.PreserveWhitespace = false;
System.Security.Cryptography.Xml.SignedXml signedXml = new System.Security.Cryptography.Xml.SignedXml(postDoc ument);
// Add a KeyInfo.
KeyInfo keyInfo = new KeyInfo();
keyInfo.AddClause(new KeyInfoX509Data(cert));
signedXml.KeyInfo = keyInfo;
signedXml.SignedInfo.CanonicalizationMethod = SignedXml.XmlDsigCanonicalizationWithCommentsUrl;
signedXml.SigningKey = cert.Key;

// Create a data object to hold the data to sign.
////System.Security.Cryptography.Xml.DataObject dataObject = new System.Security.Cryptography.Xml.DataObject();
////dataObject.Data = postDocument.SelectNodes("UserInfo");
////dataObject.Id = "MyObjectId";
// Add the data object to the signature.
////signedXml.AddObject(dataObject);
// Create a reference to be able to package everything into the message.
System.Security.Cryptography.Xml.Reference reference = new System.Security.Cryptography.Xml.Reference();
////reference.Uri = "#MyObjectId";
reference.Uri = "";
XmlDsigEnvelopedSignatureTransform env = new XmlDsigEnvelopedSignatureTransform();
reference.AddTransform(env);
// Add it to the message.
signedXml.AddReference(reference);
// Compute the signature.
signedXml.ComputeSignature();

This code throws an error at line - signedXml.SigningKey = cert.Key;
The error stack is -
Server Error in '/CertificateStore' Application.
--------------------------------------------------------------------------------
Cannot find the certificate and private key for decryption
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ComponentModel.Win32Exception: Cannot find the certificate and private key for decryption
Source Error:

Line 25: signedXml.SignedInfo.CanonicalizationMethod = SignedXml.XmlDsigCanonicalizationWithCommentsUrl;
Line 26:
Line 27: signedXml.SigningKey = cert.Key;
Line 28:
Line 29: // Create a data object to hold the data to sign.

Source File: c:\Inetpub\wwwroot\CertificateStore\App_Code\gener ateSignature.cs Line: 27
Stack Trace:

[Win32Exception (0x80004005): Cannot find the certificate and private key for decryption]
Microsoft.Web.Services.Security.X509.X509Certifica te.get_Key() +571
CertificateStore.SignatureGenerator.getSignature(X 509Certificate cert, XmlDocument postDocument) in c:\Inetpub\wwwroot\CertificateStore\App_Code\gener ateSignature.cs:27
CertificateStore.SignInAction.signIt() in c:\Inetpub\wwwroot\CertificateStore\App_Code\SignI nAction.cs:31
_Default.Button1_Click(Object sender, EventArgs e) in c:\Inetpub\wwwroot\CertificateStore\TestUI.aspx.cs :33
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEven t(String eventArgument) +107
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42

The application is built on .NET 2005.
The same code runs perfectly fine on Windows Application. But throws an error on ASP.NET
Please advice. Its very critical for me.
Reply With Quote

Reply

Tags
digital signature

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

LinkBacks (?)
LinkBack to this Thread: http://www.webforumz.com/asp-net-forum/10029-how-to-create-digital-signature.htm
Posted By For Type Date
Yahoo! Answers - Building a website? This thread Refback Jan 1st, 2007 18:20
Web Design Forums - Web design and development help and discussion This thread Refback Nov 15th, 2006 20:09

Similar Threads
Thread Thread Starter Forum Replies Last Post
Digital Preference Neosapience Free Web Site Critique 3 Oct 5th, 2007 14:16
PY Digital Caricature gpy6529 Free Web Site Critique 3 Jul 12th, 2007 01:17
Digital Designer Web JobBot Job Opportunities 0 Nov 26th, 2006 08:45
digital Organism.com courtjester Entry, Nominations and Voting 2 Nov 17th, 2003 13:07


All times are GMT. The time now is 16:03.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43