Hi,
I am loading a private .pfx key using the X509Certificate2 class by the
following line
X509Certificate2 x509 = new X509Certificate2(PrivateKeyFile,
PrivateKeyPassword);
where PrivateKeyFile and PrivateKeyPassword are strings.
This perfectly works on my computer with windows XP home and Visual Web
Developer Express.
But, when I upload this code to the production Windows Server 2003
Standart edition, the code throws the exception
System.Security.Cryptography.CryptographicException: The system cannot
find the file specified.
I am sure the file path PrivateKeyFile is correct, though I try to use
an alternative where I load the private key into a byte array and then
calling the X509Certificate2 directly on this array.
byte[] klic = File.ReadAllBytes(PrivateKeyFile);
X509Certificate2 x509 = new X509Certificate2(klic, PrivateKeyPassword);
The key file is read correctly, but the certificate construcotr throws
the same exception
System.Security.Cryptography.CryptographicException: The system cannot
find the file specified.
System.Security.Cryptography.CryptographicException.ThrowCryptogaphicException(Int32
hr) +33
System.Security.Cryptography.X509Certificates.X509Utils._LoadCertFromBlob(Byte[]
rawData, IntPtr password, UInt32 dwFlags, Boolean persistKeySet,
SafeCertContextHandle& pCertCtx) +0
System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromBlob(Byte[]
rawData, Object password, X509KeyStorageFlags keyStorageFlags) +194
System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(Byte[]
rawData, String password) +134
Muzo.Sign(String text) in
d:\weby\kvetiny-kytice.cz\3dplatba\App_Code\Muzo.cs:71
Muzo.CreateOrder(Page page, String orderNumber, String amount,
String depositFlag, String merOrderNum, String url, String description,
String md) in d:\weby\kvetiny-kytice.cz\3dplatba\App_Code\Muzo.cs:42
user_redirect_muzo.Page_Load(Object sender, EventArgs e) in
d:\weby\kvetiny-kytice.cz\3dplatba\user-redirect-muzo.aspx.cs:16
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object
o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object
sender, EventArgs e) +34
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+1061
It is strange because there is no file to open in this case.
The version of NET is 2.0.50727 on both computers.
Any suggestions?
Mirek.
|