Why wouldn't an app recognize a Certificate with a CSP of "Microsoft Software Key Storage Provider"...

David Gursky 0 Reputation points
2024-08-16T18:05:38.0333333+00:00

...but will recognize the same Cert with the CSP set to "Microsoft Enhanced RSA and AES Cryptographic Provider"?

In other words, the app fails when I import the certificate into the server's local key store like this:

certutil.exe -importpfx <certificate file path>\<certificate file>

but works if I override the CSP like this:

certutil.exe -csp "Microsoft Enhanced RSA and AES Cryptographic Provider" -importpfx <certificate file path>\<certificate file>

Here is the relevant section of code:

var store2 = X509CertificateStore.LocalMachineStore(X509CertificateStore.MyStore);
store2.OpenRead();

var coll2 = store2.FindCertificateBySubjectString(ConfigurationManager.AppSettings["<redacted>"]);

if (coll2.Count > 0) {
  var cert2 = coll2[0];
  var certType = cert2.GetType();
  var cert3 = new X509Certificate2(cert2);
  certType = cert3.GetType();
  if (cert2.SupportsDigitalSignature) {
    svc.ClientCredentials.ClientCertificate.Certificate = new X509Certificate2(cert2);
    }
  } 
else throw new Exception("Certificate attachment failed.");

var currentUser = SessionHelper.CurrentUser;
var svcAddress = Settings.Default.App_Service_WebService;

results = svc.getresultsByPersonIdentifier(PersonIdentifier.Text, identifier.PI, out responseCd, out responseMsg);

The code throws an Invalid Service Provider when it invokes the web service at the end of the snippet.

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,573 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.