3

I want to find certificate from my store but using following code i could not able to get certificate. It always return null.

code to get certificate by thumbprint

What's wrong with my code?

Update:

I have copied my certificate thumbprint by exploring store object and compare it with my thumbprint string and it return false! I think issue of interpreting string in VS2010 IDE or copy paste problem you can see that below in fig. because of this it should ignore the certificate from the list. Have anyone faced this type of issue before?

enter image description here

2
  • Your store location is CurrentUser. Are you sure that the location the certificate was stored in matches the CurrentUser location? Commented May 18, 2012 at 11:51
  • Yes i am sure that it is located there, please see my updated question Commented May 18, 2012 at 12:55

2 Answers 2

4

Well the certificate collection is empty since there's no certificate with that thumbprint. Check:

  • that the certificate is present in your current user

  • that the certificate is stored in the personal folder

Try:

  • using mmc to verify the above things

  • using X509Store store = new X509Store(StoreName.Root, StoreLocation.CurrentUser);

Edit:

Does the following return anything useful:

X509Certificate2Collection col = store.Certificates; foreach (var currCert in col) { var currThumbprint = currCert.Thumbprint; if (thumbprint.ToUpperInvariant() == currThumbprint) { x509Certificate2= currCert; break; } } 
Sign up to request clarification or add additional context in comments.

9 Comments

Yes i am sure that it is located there, please see my updated question
Will you try the code above - it's a simple custom FindByThumbprint
I have tried above code still it skip although certificate thumbprint is same. very strand issue!.
Can you write a quick char to char comparison of the two thumbprint string to see where it fails? Can't think of anything else - maybe it's a matter of encoding ( doubt that ) or some character
Hey solved that issue when i have written that thumbprint manually without copy/paste.
|
2

There might be invisible/zero length chars in your thumbprint especially at the beginning or at the end. Measure the length of thumbprint you supplied ("35ED.." ). It should be greater than what appears.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.