0

i've got some issue on reading certificates from a new smart card with a BluDrive II card reader. With old smart card no problem, but with the newest no certificate are discovered inside the card. With bit4id software i'm able to read all the cards (with all the information that i need).

            X509SecurityToken securityToken = null;
            var store = new X509Store();

            store.Open(OpenFlags.OpenExistingOnly | OpenFlags.ReadOnly);



            try
            {
                Console.WriteLine("CERTIFICATI PRESENTI: {0}",store.Certificates.Count);
                X509Certificate2Collection certs = (X509Certificate2Collection)store.Certificates;

                if (certs.Count > 0)
                {
                    int i = 1;
                    foreach (var cert in certs)
                    {
                        securityToken = new X509SecurityToken(cert);
                        Console.WriteLine(".................................................................");
                        Console.WriteLine("CERTIFICATO {0}:\n\n {1}",i++, securityToken.Certificate);
                    }
                }
                else
                {
                    Console.WriteLine("NESSUN CERTIFICATO LETTO");
                    securityToken = null;
                }

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            finally
            {
                if (store != null)

                    store.Close();
            }

I'm novice of this place, i hope in your help, thanks a lot in advance :-) Ces@re

  • I have no idea of c#, but I can't see in your code the PKCS11 library to use to access to the card. Are you sure your code is not simply reading an empty store with no relationship with any card ? – Egl Apr 28 '17 at 13:15

1 Answers1

0

You are reading the certificates not directly from your smartcard (via a PKCS#11 library) but through your operating system's certificate store (via the X509Store class). So if your OS backend is not configured properly, you won't be able to find your certificate.

mat
  • 1,645
  • 15
  • 36