Last active
June 23, 2017 02:19
-
-
Save feuerrot/0e2909047aac07334f21aae9d351c141 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
error() { | |
>&2 echo $1 | |
if [ $2 -eq "1" ] | |
then | |
exit 1 | |
fi | |
} | |
usage() { | |
echo $0 "output" | |
echo "This script generates a keyfile for stenc using /dev/random" | |
echo "The output.raw file contains the raw key" | |
echo "The output.key file contains the key in the stenc-format" | |
} | |
generate_raw() { | |
if [ -s $1.raw ] | |
then | |
error "[!] $1.raw already exists!" 0 | |
else | |
echo "[ ] Generate $1.raw" | |
dd if=/dev/random of=$1.raw bs=32 count=1 status=none | |
fi | |
} | |
generate_key() { | |
if [ -s $1.key ] | |
then | |
error "[!] $1.key already exists!" 1 | |
elif [ $(wc -c $1.raw | cut -d ' ' -f 1) -eq "32" ] | |
then | |
echo "[ ] Generate $1.key" | |
xxd -c 32 -g 32 -ps $1.raw > $1.key | |
fi | |
} | |
if [ "$#" -eq 1 ] | |
then | |
generate_raw $1 | |
generate_key $1 | |
else | |
usage | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment