24/7 ACTIVE THREAT INTELLIGENCE & NODE TELEMETRY MON - FRI: 10AM - 5PM
Home / Blog / Cybersecurity & Crypto

How to sign a file or message using gpg?

How to sign a file or message using gpg?

Many businesses are responsible for maintaining large amounts of confidential data, including customer records, medical records, financial reports, sensitive documents, and much more. It’s very common for these types of information to be transmitted via email or other services. So how can you ensure confidential data transmitted via email is kept private? How can you ensure the integrity of transmitted data?

Businesses need to ensure confidentiality, data integrity, message authentication (proof of origin), and non-repudiation (proof of content and its origin). Read on to learn more about signing and verifying authenticity of the signed file.

GnuPG offers three options for signing data:

command
--detach-sign

Create binary or ASCII-armored detached signature from input

command
--clearsign

Wrap input in plaintext signature

command
--sign

Encode input into binary or ASCII-armored output with an integrated signature

Let's take a simple example of how to sign a document.

command
gpg --clearsign file.txt

Signed file is saved as file.txt.asc and this is the content:

command
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

I want to sign this message!
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCgAdFiEEar1XMrK21wy...
-----END PGP SIGNATURE-----

Then you need to verify signed file:

command
gpg --verify file.txt.asc

You will see something like this:

command
gpg: Signature made Wed 26 Jan 2022 07:55:37 AM CET
gpg: Good signature from "alvosec info@alvosec.com"

A signed document has limited usefulness. Other users must recover the original document from the signed version, and even with clearsigned documents, the signed document must be edited to recover the original. Therefore, there is a third method for signing a document that creates a detached signature. A detached signature is created using the --detach-sig option.

command
gpg --detach-sign -o sig.gpg file.pdf

Both the document and detached signature are needed to verify the signature. The --verify option can be to check the signature.

command
gpg --verify sig.gpg file.pdf
← PREVIOUS ARTICLE
5 tips to enhance security for your XPR account
NEXT ARTICLE →
Investigation of websites and Telegram groups that are stealing private keys