dotnet add package RecursiveAI.OneCrypto.OpenPgp --prereleaseRequires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.
using RecursiveAI.OneCrypto.OpenPgp.GnuPG; var box = Keybox.Parse( File.ReadAllBytes("pubring.kbx")); foreach (var blob in box.OpenPgpBlobs) Console.WriteLine(Convert.ToHexString( blob.PrimaryFingerprint.Span));
The example is the full program below: unzip it and dotnet run. To run only the code above, paste it into Program.cs of a new dotnet new console project and dotnet run.
8E9E6980A754AFA6716D5F41FB1577AFDEAA66F1If you paste the code, copy the sample pubring.kbx from the download into the project folder too.
The full program
The sample was generated with GnuPG for the fictional user ID Keybox Example <keybox@example.org>. It starts with 00 00 00 20 01 01 00 02 4B 42 58 66 (4B 42 58 66 spells KBXf). The download lists the fingerprint and user IDs. To inspect another file, run dotnet run -- path/to/pubring.kbx.
using RecursiveAI.OneCrypto.OpenPgp; using RecursiveAI.OneCrypto.OpenPgp.GnuPG; string path = args.Length > 0 ? args[0] : "pubring.kbx"; var box = Keybox.Parse(File.ReadAllBytes(path)); foreach (var blob in box.OpenPgpBlobs) { Console.WriteLine(Convert.ToHexString(blob.PrimaryFingerprint.Span)); var certificate = PgpCertificate.FromTransferable(blob.ReadKey()); foreach (string userId in certificate.UserIds) Console.WriteLine($" {userId}"); }
dotnet run prints:
8E9E6980A754AFA6716D5F41FB1577AFDEAA66F1 Keybox Example <keybox@example.org>
Keybox.Parse throws GnuPGFormatException if the container is malformed; ReadKey() can throw OpenPgpParseException if the OpenPGP data inside it is malformed.
Variations
Count the X.509 records. The API exposes them separately from OpenPGP records.
using RecursiveAI.OneCrypto.OpenPgp.GnuPG; var box = Keybox.Parse(File.ReadAllBytes("pubring.kbx")); Console.WriteLine(box.X509Blobs.Count());
The sample prints 0.
Related recipes
The short answer
Read the .kbx file into a byte array, pass it to Keybox.Parse, and enumerate OpenPgpBlobs. Each record exposes PrimaryFingerprint; use ReadKey() to get the OpenPGP packets when you also need user IDs. If you have the file already, there is no need to import it into another keyring or launch GnuPG.
What is pubring.kbx?
It’s a GnuPG public-key container, not a single exported key. A keybox contains a header and a sequence of binary records, called blobs. The OneCrypto format notes describe the supported OpenPGP and X.509 records. OpenPGP records can be decoded as keys. X.509 records expose their certificate bytes as DER; they do not appear in OpenPgpBlobs.
The file path matters. Pass the keybox file itself, not the GnuPG home directory. A legacy pubring.gpg or binary gpg --export stream is a sequence of transferable keys instead of a keybox; use LegacyKeyring for that format. If your input is a home directory and you want the library to choose between pubring.kbx and pubring.gpg, use GnuPGHome.ReadPublicKeys() instead.
How do I display GnuPG public-key details without importing them?
Read the public file and print only the fields you need. The short snippet uses the fingerprint in each record’s metadata. The full example decodes each OpenPGP key and reads the user IDs from its certificate, so it can show more than one per key. No private-key file, passphrase or running GnuPG process is involved.
Treat the result as an inventory, not a trust decision. A user ID is text associated with the key, not proof of ownership of the name or email address. Reading the public keybox also doesn’t read the separate trustdb.gpg ownertrust records. If you expected OpenPGP keys but the list is empty, check whether the file contains X.509 records or whether you opened a different keybox from the one you meant to inspect.