Skip to content

Instantly share code, notes, and snippets.

@cypnk
Created October 16, 2017 23:44
Show Gist options
  • Save cypnk/b37bafa923d614d4f43a7e8e55870511 to your computer and use it in GitHub Desktop.
Save cypnk/b37bafa923d614d4f43a7e8e55870511 to your computer and use it in GitHub Desktop.
Verify a file with a given public key (best for files signed with "sign.sh")
#!/bin/bash
# Verify a signed file with the specified public key
# Signature file
SRCF=$1
# Public key location
PUBK=$2
# Signature algorithm (defaults to SHA-512)
ALGO=${3:-sha512}
# Algo file
ALGF=$SRCF.$ALGO.sig
# Check for signature file
if [ ! -f "$ALGF" ]; then
echo "Signature file must be in the same directory"
exit
fi
if [ -f "$PUBK" ]; then
if [ -f "$SRCF" ]; then
openssl dgst -$ALGO -verify $PUBK -signature $ALGF $SRCF
else
echo "Source file not found"
fi
else
echo "Public key not found"
fi
exit
# To use this, run:
# sh verify.sh /path/to/file.ext /path/to/publickey.pub
# The signature file should be there in "file.ext.sha512.sig" format
# Or if a different algorithm was used, E.G. SHA-256:
# sh verify.sh /path/to/file.ext /path/to/publickey.pub sha256
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment