0

I have a Smart Card that I use to sign my documents. Now I am developing a c# application that can access the USB Reader with the card, retrieve the certificate and sign an XML. The ideal solution is to "copy" the certificate inside an X509Certificate2 object.

I'm using this code right now:

List<X509Certificate2> certificates = new List<X509Certificate2>();
CspParameters cspParameters = new CspParameters(1, "Microsoft Base Smart Card Crypto Provider");
RSACryptoServiceProvider rsaProvider = new RSACryptoServiceProvider(cspParameters);
    
X509Store x509Store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
x509Store.Open(OpenFlags.ReadOnly);
foreach (X509Certificate2 cert in x509Store.Certificates)
{
  certificates.Add(cert);
}

Inside the list I have some certificates, but not the one that is stored inside the Smart Card. Any suggestions?

x00
  • 13,643
  • 3
  • 16
  • 40
meltigel
  • 11
  • 5
  • Does this help: (https://stackoverflow.com/questions/22236116/find-certificate-on-smartcard-currently-on-reader) ? – Ryan Wilson Aug 11 '20 at 15:34
  • I'm using the code in the answer, but with no results... – meltigel Aug 11 '20 at 15:38
  • Note that the public part of the certificate can be safely copied to user cert store and only the private key has to remain on the smart card. Also if the smart card is present in the reader, the cert should be [automatically put in the user keystore](https://stackoverflow.com/questions/20120636/getting-smartcard-certificate-into-windows-service-local-store-mmc). – Wiktor Zychla Aug 11 '20 at 18:14
  • Will read and try to get the certificate... Any suggestions on how to copy inside a X509Certificate2 object? So I can use it to sign the documents directly via code... – meltigel Aug 12 '20 at 07:09

0 Answers0