Christian Gollhardt
Christian Gollhardt

Reputation: 17004

How to find in store the certificate I need?

For one of my applications I am developing against the TeleCashAPI (Internet Payment Gateway). I need to send a client certificate (p12) on each call.

Until now I have loaded the Client Certificate via Filesystem

public void AddCertificate(X509Certificate certificate)
{
    WebRequest.ClientCertificates.Add(certificate);
}

Now my customer want to have it more generic. It should be installed on the client machine (which is talking to this api). I still know what is the password, but I don't know the certificate.

How can I get the Certificate?

From this answer, I see how I can get the whole list:

X509Store store = new X509Store("My");

store.Open(OpenFlags.ReadOnly);

foreach (X509Certificate2 mCert in store.Certificates){
    //TODO's
}

But how I find the certificate I specificly want to have? Is this even posssible?

I am realy new to this topic.


To be a little bit more clear:

The certificate is installed by doubleclick. I can not controll this process. My Task is, to find the certificate, which is for TeleCash.

Upvotes: 0

Views: 573

Answers (1)

Narek Arzumanyan
Narek Arzumanyan

Reputation: 616

To know certificate hash - double click on certificate -> details -> Thumbprint

foreach (X509Certificate2 mCert in store.Certificates)
{
    if(mCert.Thumbprint.ToLower()=="Your Certificat hash")
    {
        //TODO
    }
}

Upvotes: 3

Related Questions