„sign.sh“ hinzufügen

This commit is contained in:
2022-02-23 18:32:29 +01:00
parent 15401ca87c
commit 89c83dfbb0

25
sign.sh Normal file
View File

@@ -0,0 +1,25 @@
#!/bin/bash
# Sign a file with a private key using OpenSSL
# Encode the signature in Base64 format
#
# Usage: sign <file> <private_key>
#
# NOTE: to generate a public/private key use the following commands:
#
# openssl genrsa -aes128 -passout pass:<passphrase> -out private.pem 2048
# openssl rsa -in private.pem -passin pass:<passphrase> -pubout -out public.pem
#
# where <passphrase> is the passphrase to be used.
filename=$1
privatekey=$2
tmpfile="$(mktemp)"
if [[ $# -lt 2 ]] ; then
echo "Usage: sign <file> <private_key>"
exit 1
fi
openssl dgst -sha256 -sign $privatekey -out ${tmpfile} $filename
openssl base64 -in ${tmpfile} -out signature.sha256
rm ${tmpfile}