Sign and verify a file using OpenSSL command line tool. It exports the digital signature in Base64 format. - JohnHau/mis GitHub Wiki

sign.sh #!/bin/bash

Sign a file with a private key using OpenSSL

Encode the signature in Base64 format

Usage: sign <private_key>

NOTE: to generate a public/private key use the following commands:

openssl genrsa -aes128 -passout pass: -out private.pem 2048

openssl rsa -in private.pem -passin pass: -pubout -out public.pem

where is the passphrase to be used.

filename=$1 privatekey=$2

if $# -lt 2 ; then echo "Usage: sign <private_key>" exit 1 fi

openssl dgst -sha256 -sign $privatekey -out /tmp/$filename.sha256 $filename openssl base64 -in /tmp/$filename.sha256 -out signature.sha256 rm /tmp/$filename.sha256

verify.sh #!/bin/bash

Verify a file with a public key using OpenSSL

Decode the signature from Base64 format

Usage: verify <public_key>

NOTE: to generate a public/private key use the following commands:

openssl genrsa -aes128 -passout pass: -out private.pem 2048

openssl rsa -in private.pem -passin pass: -pubout -out public.pem

where is the passphrase to be used.

filename=$1 signature=$2 publickey=$3

if $# -lt 3 ; then echo "Usage: verify <public_key>" exit 1 fi

openssl base64 -d -in $signature -out /tmp/$filename.sha256 openssl dgst -sha256 -verify $publickey -signature /tmp/$filename.sha256 $filename rm /tmp/$filename.sha256

⚠️ **GitHub.com Fallback** ⚠️