Pgp.Revoke signs a notice to stop using the key. Share it as a public certificate, not a private key.
dotnet add package RecursiveAI.OneCrypto.OpenPgpRequires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.
using RecursiveAI.OneCrypto; var key = Pgp.GenerateKey("Demo key"); var revoked = Pgp.Revoke(key); File.WriteAllBytes("revoked.asc", revoked.ExportPublic(armor: true)); Console.WriteLine("Wrote revoked.asc");
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.
Wrote revoked.ascThe full program
The download generates a throwaway key in memory, writes revoked.asc, and reads that public file back to show its primary-key state. It doesn’t read or save a private key file.
using RecursiveAI.OneCrypto; using RecursiveAI.OneCrypto.OpenPgp; var key = Pgp.GenerateKey("Demo key"); var revoked = Pgp.Revoke(key); File.WriteAllBytes("revoked.asc", revoked.ExportPublic(armor: true)); Console.WriteLine("Wrote revoked.asc"); var saved = PgpCertificate.Parse( File.ReadAllBytes("revoked.asc")); Console.WriteLine(saved.Primary.StateAt(DateTimeOffset.UtcNow).Reason); Console.WriteLine($"Secret material: {saved.HasSecretKeyMaterial}");
dotnet run prints:
Wrote revoked.asc The key is revoked. Secret material: False
Variations
Revoke a key you already own. Export that key to secret.asc. For example, replace YOUR_KEY_FINGERPRINT with the fingerprint of the key you mean to revoke:
(umask 077; gpg --armor --export-secret-keys YOUR_KEY_FINGERPRINT > secret.asc)Replace Program.cs with the code below and run it in the folder containing secret.asc. If the exported key is protected, supply its passphrase in the PGP_KEY_PASSWORD environment variable; leave that variable unset for an unprotected key. Keep secret.asc private. Share only revoked.asc, and only when you intend others to stop using the key.
using RecursiveAI.OneCrypto; using RecursiveAI.OneCrypto.OpenPgp; var key = PgpCertificate.Parse( File.ReadAllBytes("secret.asc")); var password = Environment.GetEnvironmentVariable( "PGP_KEY_PASSWORD"); var revoked = Pgp.Revoke(key, password); File.WriteAllBytes("revoked.asc", revoked.ExportPublic(armor: true)); Console.WriteLine("Wrote revoked.asc");
With a throwaway exported key, dotnet run printed:
Wrote revoked.ascUse a password-protected key. Replace the key generation and revocation lines with these. The password is for this throwaway key only.
const string password = "demo password"; var key = Pgp.GenerateKey("Demo key", password); var revoked = Pgp.Revoke(key, password);
If the password doesn’t unlock the secret primary key, Pgp.Revoke throws PgpException before the example writes the file.
Related recipes
The short answer
Install RecursiveAI.OneCrypto.OpenPgp, call Pgp.Revoke with the certificate that holds your secret primary key, and export the result with ExportPublic(armor: true). The output is a text-armored public key block carrying a signed primary-key revocation. It is not a bare revocation signature. Creating the file does not publish it or change copies that other people already hold.
What does revoking an OpenPGP key mean?
A revocation is a signed statement about a key, not a deletion. The public key still identifies the same key, but people and software that receive and accept the revocation know to stop using it. Pgp.Revoke creates a hard revocation with “no reason given.” In OneCrypto’s key-management rules, the key counts as revoked even when OneCrypto checks a signature made before the revocation, so it isn’t a way to retire a key only from today onward. It applies to the primary key, not just one user ID or subkey. To set a reason or make a soft revocation (for example, PgpRevocationReason.Retired), use PgpKeyEditor.RevokeKey instead.
The file can be sent to the people who use the key or distributed through the channels where you published the original. If you are preparing a revocation as a backup instead, keep it private until you intend to revoke the key. It contains no secret key material, but someone who obtains the file can distribute the signed revocation.
Can you revoke an OpenPGP key without the private key?
You need the secret primary key to make a new revocation with Pgp.Revoke. An existing valid revocation can still be shared if you later lose access to that key. A public certificate without a revocation is not enough to create one, even if you know the fingerprint or still have a secret subkey.
If your workflow calls for a smaller revocation certificate, OneCrypto distinguishes the full public certificate returned by Pgp.Revoke from the compact form from PgpKeyEditor.CreateRevocationCertificate: the public primary key plus one key revocation signature. Both are distinct from a bare signature packet. See the OpenPGP docs and RFC 9580’s key revocation signature type.