---
title: "Look up a certificate serial number in a DER CRL in C#"
url: https://recursiveai.org/onecrypto/cookbook/find-serial-in-certificate-revocation-list/
description: "Parse a local DER certificate revocation list and look up a certificate serial number in C#. A match shows list membership, not trust."
version: "0.4.0-preview.2"
---

# Look up a certificate serial number in a DER CRL in C#

**OneCrypto** is a free, open-source cryptography library for .NET from Recursive AI. MIT or Apache-2.0, preview, no native dependencies.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OneCrypto) · [GitHub](https://github.com/recursive-ai-oss/onecrypto-csharp) · [Docs](https://recursiveai.org/onecrypto/docs/) · [Download example (.zip)](https://recursiveai.org/onecrypto/cookbook/find-serial-in-certificate-revocation-list/find-serial-in-certificate-revocation-list.zip)

Use `Find` to look up hex serial `80` in `sample.crl`. The download’s certificate revocation list uses DER, a standard binary encoding.

```shell
dotnet add package RecursiveAI.OneCrypto --prerelease
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
using RecursiveAI.OneCrypto;

var der = File.ReadAllBytes("sample.crl");
var crl = CertificateRevocationList.Parse(der);
var serial = Convert.FromHexString("80");
var entry = crl.Find(serial);
Console.WriteLine(entry is not null);
```

Unzip [the example](https://recursiveai.org/onecrypto/cookbook/find-serial-in-certificate-revocation-list/find-serial-in-certificate-revocation-list.zip), then `dotnet run`.

```text
True
```

## The full program

The binary `sample.crl` is a synthetic list signed with a throwaway key for this example. Its decoded issuer and only entry are:

```text
Issuer: CN=Workshop Test CA
Serial Number: 80
Revocation Date: Jan  1 00:00:00 2026 GMT
```

```csharp
using RecursiveAI.OneCrypto;

var der = File.ReadAllBytes("sample.crl");
var crl = CertificateRevocationList.Parse(der);
foreach (string serial in new[] { "80", "0080", "81" })
{
    var entry = crl.Find(Convert.FromHexString(serial));
    Console.WriteLine(entry is null
        ? $"{serial}: not listed"
        : $"{serial}: listed on {entry.RevocationDate:O}");
}
```

`dotnet run` prints:

```text
80: listed on 2026-01-01T00:00:00.0000000+00:00
0080: listed on 2026-01-01T00:00:00.0000000+00:00
81: not listed
```

`Parse` throws `X509ParseException` for malformed CRL data; `Find` returns `null` when the serial number isn’t listed. Neither call verifies the CRL’s signature or whether it applies to a certificate.

## Variations

**Read a PEM list.** Append this to the snippet at the top to try the PEM reader using the same list. For an existing PEM file, pass its text to `FromPem` instead of calling `ToPem`.

```csharp
string pem = crl.ToPem();
var fromPem = CertificateRevocationList.FromPem(pem);
Console.WriteLine(fromPem.Find(new byte[] { 0x80 }) is not null);
```

```text
True
```

## Related recipes

- [Validate an X.509 certificate chain](https://recursiveai.org/onecrypto/cookbook/validate-x509-certificate-chain/)
- [Compare X.509 distinguished names](https://recursiveai.org/onecrypto/cookbook/compare-x509-distinguished-names/)
- [Preproduce an OCSP response](https://recursiveai.org/onecrypto/cookbook/preproduce-ocsp-response/)

## The short answer

Pass the bytes of the local DER CRL to `CertificateRevocationList.Parse`, then call `Find` with the serial number as bytes, most significant byte first. When you have hex text, turn it into bytes with `Convert.FromHexString` rather than passing the text’s UTF-8 bytes. A match gives you the recorded revocation date; `null` means only that the serial number wasn’t found in that file.

## How do you check a certificate serial number against a CRL?

Use the serial number of the certificate you’re checking, not its thumbprint, the issuer’s serial number, or the CRL number. If you already have a parsed OneCrypto `Certificate`, its `SerialNumber.Span` is in the byte order `Find` expects. If you’re copying a displayed hex number, omit formatting such as `0x` prefixes or separators before decoding it. `Find` takes the INTEGER’s content bytes, not the ASN.1 tag and length.

`Find` scans the entries and ignores leading zero bytes: DER can encode a positive value whose high bit is set with a leading `00`. That’s why `80` and `0080` find the same entry, but `81` doesn’t. The property `RevocationDate` comes from the matched entry; it’s not the date the list was issued.

## Does a missing CRL entry mean a certificate isn’t revoked?

Not by itself. A [CRL](https://www.rfc-editor.org/rfc/rfc5280.html#section-5) covers a particular issuer and scope, and applies within a time window. Before relying on a CRL for a revocation decision, check that it’s applicable to the certificate, that it’s current for the time you’re checking, and that it was signed by an authorized issuer. A downloaded file can parse correctly without being a valid source of revocation information.

For a delta CRL, a missing entry doesn’t rule out a matching entry in the complete list it updates. For an indirect CRL, entries can cover certificates issued by more than one CA; a lookup by serial alone doesn’t resolve the certificate issuer. Both cases are handled as part of [CRL validation in RFC 5280](https://www.rfc-editor.org/rfc/rfc5280.html#section-6.3), not by searching one file. Use `Find` to inspect a list and a validator to decide whether a certificate can be trusted.
