Choosing Certificate through CNPJ

Asked

Viewed 125 times

0

I have this function which searches the certificate by serial:

 public static X509Certificate2 EscolherCertificado()
    {
        var store = new X509Store("MY", StoreLocation.CurrentUser);
        X509Certificate2 x509 = null;

        var Key = new RSACryptoServiceProvider();
        store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
        X509Certificate2Collection collection = store.Certificates;
        X509Certificate2Collection fcollection = collection.Find(X509FindType.FindBySerialNumber, "serialcertificadoaqui", false);
        if (fcollection.Count == 1)
        {
            return fcollection[0];
        }
        else { return null; }

    }

But at first I won’t know the serial, how can I fetch the certificate serial through a function ? Without the user needing to type, it is possible ?

1 answer

0


I managed to solve by changing this line:

X509Certificate2Collection fcollection = collection.Find(X509FindType.FindBySerialNumber, "serialcertificadoaqui", false);

for this:

 X509Certificate2Collection fcollection = collection.Find(X509FindType.FindBySubjectName, doc, false);

In doc I pass the cnpj only numbers, and he managed to find.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.