Re: I want to read a .pfx and use the private key to sign a document, is that "that" bad?

"hubble" <max.favilli@xxxxxxxxx> wrote in message news:1188229164.237866.115640@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
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);


X509Certificate2 cert = new X509Certificate2(xml, "");
RSACryptoServiceProvider crypto = cert.PrivateKey as


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, " ");

"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.
John Saunders | MVP - Windows Server System - Connected System Developer