I am trying to sign an xml document with a private key, reading the
key from a .pfx file. The code following.
string xml;
xml = Request.MapPath("/rsacert.pfx");
xml = HttpUtility.HtmlDecode(xml);
Trace.Write(xml);
Response.Write("<p/>");
X509Certificate2 cert = new X509Certificate2(xml, "");
RSACryptoServiceProvider crypto = cert.PrivateKey as
RSACryptoServiceProvider;
Response.Write("<p/>");
Response.Write(crypto.ToString());
If execute the code on my laptop it works (I have .net 2.0 + compact +
sdk + visual studio installed), if upload the code on one of the test
servers (windows 2003 server + .net 2.0 + compact + sdk, but no VS2005
of course) doesn't work and an exception occurs.
I get a security exception from .net "The system cannot find the file
specified." when executing the following line of code (taken from the
source code, xml is file name and it's correct):
X509Certificate2 cert = new X509Certificate2(xml, " ");
I think it's was they talk about here:
http://support.microsoft.com/kb/915980
As they say the hotfix need to be requested to the customer support, I
will on monday, but they also add if your application run on "Full
trust" it shouldn't happen. My application is running on "Full Trust".
Has anyone got the hotfix? Does it really fix the problem?
I generated the certificate using makecert as explained here:
http://code.google.com/support/bin/answer.py?answer=71864#DotNetTools
Since I understood (reading articles here and there on the web) that
the problem is related to certificates not installed in the
certificates store of windows 2003 server. I right clicked on the .pfx
file and choose "import", I can see it in the certificates store, but
still doesn't work, same exception, nothing changed.
I am lost... I hate the world... Everyone is evil... Programming
sucks... I hate certificates... I want a world free of them...
Please HELP!
hubble - 29 Aug 2007 20:11 GMT
Really no one did that in the past?
John Saunders [MVP] - 30 Aug 2007 21:29 GMT
>I am trying to sign an xml document with a private key, reading the
> key from a .pfx file. The code following.
[quoted text clipped - 21 lines]
> source code, xml is file name and it's correct):
> X509Certificate2 cert = new X509Certificate2(xml, " ");
"The system cannot find the file specified." does not sound like a security
exception. Why did you call it that?
This is a "file not found" exception. So, what file can't it find? The one
specified in "xml"? If so, check to see if the file exists before you use it
to create the certificate. Display the full path if you get an exception.

Signature
--------------------------------------------------------------------------------
John Saunders | MVP - Windows Server System - Connected System Developer