Submit Your Article Webforumz RegistrationAnnouncements Contact Webforumz StaffContact
Home Resources Blogs Meet the Team Contact Register
 

Go Back   WebForumz.com > The Code > .NET

Reply
 
LinkBack (2) Thread Tools
Old November 2nd, 2006, 09:13 AM   2 links from elsewhere to this Post. Click to view. #1
New Member
 

Join Date: Nov 2006
Location: New Delhi
Age: 32
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 maggee1076 is on a distinguished road
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.
maggee1076 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Bookmarks

Tags
digital signature


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

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Digital Preference Neosapience Full Website Reviews 3 October 5th, 2007 11:16 AM
PY Digital Caricature gpy6529 Full Website Reviews 3 July 11th, 2007 10:17 PM
digital Organism.com courtjester Entry, Nominations and Voting 2 November 17th, 2003 10:07 AM


Search Engine Optimization by vBSEO 3.2.0 RC8