How to retrieve certificate from a certificate store by Common Name

Anonymous
2021-04-09T15:14:11.237+00:00

Using C# how can we retrieve certificate from a certificate store by using Common name . Any help would be greatly appreciated

Developer technologies | C#
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Daniel Zhang-MSFT 9,656 Reputation points
    2021-04-12T06:24:13.65+00:00

    Hi,
    Please try the flumeware's code and check if it works for you.
    Code:

    X509Store store = new X509Store(storeName, StoreLocation.CurrentUser);  
      
    store.Open(OpenFlags.ReadOnly);  
    X509Certificate2Collection col = store.Certificates.Find(X509FindType.FindBySubjectName, commonName,false);  
    

    Best Regards,
    Daniel Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentationto enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

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.