# Verify a detached file signature

[Read this guide on KeySigner](https://keysigner.io/integrations/guides/verify-a-detached-file-signature/)

Check which key signed a sample file, then change one byte and confirm the same signature fails.

## Before you start

- Use a disposable signed file from a test publisher. Keep its original bytes, detached signature and public key. Get the expected public key or OpenPGP fingerprint from a trusted channel independent of the download.
- Use the tool, format and algorithm specified by the publisher. The OpenSSL example uses RSA with SHA-256. The GnuPG example uses an OpenPGP detached signature and a test key in your local keyring.

## Data and access

- **Shared or checked**. The verifier reads the sample file, detached signature and public key. It checks the signature against those exact file bytes.
- **Check separately**. A valid signature does not identify an authorized publisher without a trusted key record. Download or deployment approval is separate.

## 1. OpenSSL

Use the expected public key in public.pem. Run the command with the sample RSA signature and original file. Repeat with a copy of sample.txt that you changed, keeping the signature and public key fixed.

~~~
openssl dgst -sha256 -verify public.pem -signature message.sig sample.txt
~~~

**Check.** “Verified OK” and exit status zero identify a successful verification of the original file.

## 2. GnuPG

Compare the imported public key’s full fingerprint with the one the publisher supplied through a trusted channel. Pass both the signature and the file explicitly. On success, check the signer fingerprint. A warning about trust in the key’s owner is a separate check from whether the signature matches the file.

~~~
gpg --verify sample.txt.sig sample.txt
~~~

**Check.** Compare the full signer fingerprint with the trusted fingerprint before accepting the result.

## 3. Try a changed copy

Keep the good sample as a control. Change a copy and repeat verification using the same expected key and detached signature. Your verification step should fail on the changed copy and still pass on the original.

**Check.** The changed copy gives a failed verification and nonzero exit status. Recheck the original with the same key and signature.

## Check your result

The original file verifies with the expected key, and the changed file fails verification. Keep the expected signer identity in the release policy so the check remains meaningful when keys change.

### What we tested

**Tested on November 17, 2026.** We used OpenSSL 4.1.0 and GnuPG 2.5.22 on macOS with disposable keys. Each verified the original sample and rejected a changed copy. The test covered local file verification.

[How to verify your setup](https://keysigner.io/integrations/verify-a-setup/)

## If you get stuck

### The unmodified sample fails verification

Check that the signed file was transferred byte for byte and the signature is for that exact file. For OpenSSL, confirm the signature algorithm and digest. For GnuPG, check that the expected public key is in the active keyring.

## Tools in this guide

- [OpenSSL](https://keysigner.io/integrations/openssl/)
  - [Review certificate verification and trust options](https://docs.openssl.org/master/man1/openssl-verification-options/)
  - [Verify detached signatures with OpenSSL](https://docs.openssl.org/3.5/man1/openssl-dgst/)
- [GnuPG](https://keysigner.io/integrations/gnupg/)
  - [Verify signatures and signing key fingerprints](https://gnupg.org/download/integrity_check.html)
  - [Check GnuPG’s signer fingerprint option](https://gnupg.org/documentation/manuals/gnupg26/gpg.1.html)

## Setup instructions

- [Verify a file signature with OpenSSL dgst](https://docs.openssl.org/master/man1/openssl-dgst/)
- [Check GnuPG’s detached signature arguments](https://www.gnupg.org/documentation/manuals/gnupg26/gpg.1.html)
- [Check a Linux package signature](https://keysigner.io/integrations/guides/check-linux-package-signatures/)
- [Compare the signed archive with a KeySigner release approval](https://keysigner.io/integrations/guides/check-an-approved-package-with-detached-signatures/)

[More guides for this task](https://keysigner.io/integrations/tasks/review-code-and-releases/)
