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.
|
|
|
|
|
![]() |
||
How To: Create Digital Signature
|
||
| Notices |
![]() |
|
|
LinkBack (2) | Thread Tools |
|
|||
|
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. |
|
|
![]() |
| Tags |
| digital signature |
| Thread Tools | |
|
|
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 |