Blog | G5 Cyber Security

Verify Downloaded Files with a Private Key

TL;DR

Yes, you can securely verify downloaded files if you control the private key used to sign them and have a trusted verification algorithm. This guide explains how using digital signatures.

How Digital Signatures Work

Digital signatures provide assurance that a file hasn’t been tampered with since it was signed, and that it genuinely came from someone possessing the private key. Here’s a breakdown:

Steps for Secure Verification

  1. Choose a Signing Algorithm: Select a robust algorithm like RSA-SHA256 or ECDSA with SHA-256. These are widely used and considered secure. Avoid older, weaker algorithms.
  2. Generate Key Pair: If you haven’t already, generate a private/public key pair using a tool like OpenSSL:
    openssl genrsa -out private.pem 2048
    openssl rsa -in private.pem -pubout -out public.pem
  3. Sign the File: Use your private key to sign the file. This creates a signature file (e.g., file.sig).
    openssl dgst -sha256 -sign private.pem -out file.sig file.txt
  4. Distribute File and Signature: Make both the original file (file.txt) and its signature (file.sig) available for download. Never share your private key!
  5. Verification Process (Receiver Side): The receiver needs to verify the signature using your public key.
    • Obtain Public Key: Ensure the receiver obtains a trustworthy copy of your public key. This is critical – a compromised public key defeats the entire process.
    • Verify Signature: Use OpenSSL or another suitable tool to verify:
      openssl dgst -sha256 -verify public.pem -signature file.sig file.txt

      A successful verification will output something like Verified OK.

  6. Handle Verification Failures: If the signature doesn’t verify, it means one of these things:
    • The file has been altered since signing.
    • The wrong public key was used.
    • The signature file is corrupted or does not match the file.

    In any case, do not trust the file.

Important Considerations

Exit mobile version