Sample code for 30+ languages & platforms
.NET Core C#

Find Certificate by Serial Number

See more Cert Store Examples

Demonstrates how to find a certificate having the specified hexadecimal serial number.

Note: Requires Chilkat v10.1.2 or later.

Chilkat .NET Core C# Downloads

.NET Core C#
bool success = false;

Chilkat.CertStore certStore = new Chilkat.CertStore();

// This example will search the certs on connected USB tokens and smartcards.
string argNotUsed = "";
success = certStore.OpenSmartcard(argNotUsed);
if (success == false) {
    Debug.WriteLine(certStore.LastErrorText);
    return;
}

// Find the certificate having a serial number = "48FC93B46055948D36A7C98A89D69416".
string hexSerial = "48FC93B46055948D36A7C98A89D69416";
Chilkat.JsonObject json = new Chilkat.JsonObject();
json.UpdateString("serial",hexSerial);

Chilkat.Cert cert = new Chilkat.Cert();
success = certStore.FindCert(json,cert);
if (success == true) {
    // Show the serial number and subject CN
    Debug.WriteLine("Found: " + cert.SerialNumber + ", " + cert.SubjectCN);
}
else {
    Debug.WriteLine("Not found.");
}