I tryed to search sertificates in local store by serial with the following code:
X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
var certSerial = "18 99 ac c2 1e ed 69 ae"; //copied from Windows Certificates view tool
certSerial = certSerial.Replace(" ", string.Empty).ToUpper();
var foundCerts = store.Certificates.Find(
X509FindType.FindBySerialNumber,
certSerial ,
true);
…And found nothing. However then I looked into that store in Debug mode and coppied the serial of certificate I wanted to find – 1899ACC21EED69AE and changed the certSerial variable into:
var certSerial = "1899ACC21EED69AE";
it returns me the right certificate.
In Debug both variables seems the same – what should I do to make the first code work? I just don’t understand why it behaves so.
As explain in FindBySerialNumber, the serial number must be in reverse order because it is an integer.
Retype you string in :
When I paste it in my editor I received :