snipeit-scanner/encryptKey

40 lines
825 B
Bash
Executable File

#!/bin/bash
KEY=$1
KEYLENGTH=${#KEY}
TOKEN=$3
if [ "$#" -ne 3 ]; then
echo "Usage: ${0} pin \"User Name\" \"token\""
echo "With:"
echo -e " pin\t\t numeric pin with 1 to 32 numbers"
echo -e " User Name\t your name"
echo -e " token\t\t the token from Snipe"
exit 1
fi
if ! [[ $KEY =~ ^[0-9]+$ ]];
then
echo "Invalid key"
exit 1
fi
if [ $KEYLENGTH -gt 32 ]; then
echo "Key is too long"
exit 1
fi
while [ $KEYLENGTH -lt 32 ]
do
KEY="0${KEY}"
KEYLENGTH=${#KEY}
done
echo -n $TOKEN >/tmp/apitoken_snipe
K=$(echo -n $KEY | xxd -p -c 100)
ENC=$(openssl enc -aes-256-ecb -e -in /tmp/apitoken_snipe -K $K -base64 -A)
echo ""
echo ""
echo "Insert the following (only inbetween the ---) into the scanner_users.json file:"
echo "---"
echo "{\"name\":\"${2}\", \"token\": \"${ENC}\"},"
echo "---"
rm /tmp/apitoken_snipe