المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Unable to read Private Key as XML String



C# Programming
08-21-2009, 04:35 PM
My C# web application is trying to read the Private Key of the our own digital certificate installed on Windows 2008 Server, when it needs to decrypt the data received from the web request.

Following is the code:

X509Certificate2 cert = GetCert(thumbPrintOfPrivKey, StoreName.My, Store********.CurrentUser);

try
{

string privateKey = cert.PrivateKey.ToXmlString(true);
log.Info("Retrieved Private Key....");

rsacsp.FromXmlString(privateKey);

}
catch(Exception e)
{
string msg = "Unable to Read the Private Key: ";
log.Error(msg + e.Message);

throw new Exception(msg, e);
}

And following line of above-mentioned code throws an error.

string privateKey = cert.PrivateKey.ToXmlString(true);

The error which I get is: - "The system cannot find the file specified."
And following is the stack Trace:

at System.Security.Cryptography.Utils.CreateProvHandle(CspParameters parameters, Boolean randomKeyContainer)
at System.Security.Cryptography.Utils.GetKeyPairHelper(CspAlgorithmType keyType, CspParameters parameters, Boolean randomKeyContainer, Int32 dwKeySize, SafeProvHandle& safeProvHandle, SafeKeyHandle& safeKeyHandle)
at System.Security.Cryptography.RSACryptoServiceProvider.GetKeyPair()
at System.Security.Cryptography.RSACryptoServiceProvider..ctor(Int32 dwKeySize, CspParameters parameters, Boolean useDefaultKeySize)
at System.Security.Cryptography.RSACryptoServiceProvider..ctor(CspParameters parameters)
at System.Security.Cryptography.X509Certificates.X509Certificate2.get_PrivateKey()
at SSO.SSOUtility.ProcessData(String decodedSig, String decodedToken, String combined) in


When I checked my Application Event Logs to see what exactly is happening, the event log showed that the "CertificateServicesClient" has stopped. And I noticed that it gets started automatically when I logon to the server.

Can anybody please help me in finding the reason as to why this service(?) stops and starts automatically, and how can we restart it immediately the moment it stops?

Thanks in advance.

-----
Ajay Jadhav
http://www.divinet.co.in