Merge 4a1f39546d into e38696a0ac
commit
45a4620f39
|
|
@ -0,0 +1,6 @@
|
|||
# shellcheck shell=bash
|
||||
|
||||
alias ep="encrypt-payload"
|
||||
alias dp="decrypt-payload"
|
||||
alias enc="encrypt-payload"
|
||||
alias dec="decrypt-payload"
|
||||
|
|
@ -100,6 +100,7 @@ plugins/available/battery.plugin.bash
|
|||
plugins/available/blesh.plugin.bash
|
||||
plugins/available/cmd-returned-notify.plugin.bash
|
||||
plugins/available/colors.plugin.bash
|
||||
plugins/available/cryptography.plugin.bash
|
||||
plugins/available/direnv.plugin.bash
|
||||
plugins/available/dirs.plugin.bash
|
||||
plugins/available/docker-machine.plugin.bash
|
||||
|
|
|
|||
|
|
@ -0,0 +1,66 @@
|
|||
# shellcheck shell=bash
|
||||
|
||||
function encrypt-payload() {
|
||||
PAYLOAD=$1
|
||||
KEY=$2
|
||||
ALGO=${3:-aes-256-cbc}
|
||||
|
||||
# exit with message if payload is empty string
|
||||
if [[ -z "$PAYLOAD" ]]; then
|
||||
echo "[x] Payload is empty!"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# create random key if not provided
|
||||
if [[ -z "$KEY" ]]; then
|
||||
KEY=$(echo "$RANDOM$RANDOM" | md5sum - | head -c 13)
|
||||
echo "[!] Key not provided, therefore choosen a random string -> $KEY" 1>&2
|
||||
echo "[!] To hide this message, provide the key as second argument or redirect stderr to /dev/null" 1>&2
|
||||
fi
|
||||
|
||||
if [[ -f "$1" ]]; then
|
||||
# if payload file then encrypt with -in
|
||||
OUTFILE=$(mktemp)
|
||||
if ! openssl enc "-$ALGO" -a -A -e -pbkdf2 -pass pass:"$KEY" -in "$PAYLOAD" -out "$OUTFILE"; then
|
||||
echo "[x] Something went wrong!"
|
||||
rm -rf "$OUTFILE"
|
||||
else
|
||||
echo "[+] Saved the encrypted file to '$OUTFILE'"
|
||||
fi
|
||||
else
|
||||
# if payload file then encrypt with stdin
|
||||
echo -ne "$1" | openssl enc "-$ALGO" -a -A -e -pbkdf2 -pass pass:"$KEY"
|
||||
fi
|
||||
}
|
||||
|
||||
function decrypt-payload() {
|
||||
PAYLOAD=$1
|
||||
KEY=$2
|
||||
ALGO=${3:-aes-256-cbc}
|
||||
|
||||
# exit with message if payload is empty string
|
||||
if [[ -z "$PAYLOAD" ]]; then
|
||||
echo "[x] Payload is empty!"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# create random key if not provided
|
||||
if [[ -z "$KEY" ]]; then
|
||||
echo "[x] Key is empty!"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [[ -f "$1" ]]; then
|
||||
# if payload file then encrypt with -in
|
||||
OUTFILE=$(mktemp)
|
||||
if ! openssl enc "-$ALGO" -a -A -d -pbkdf2 -pass pass:"$KEY" -in "$PAYLOAD" -out "$OUTFILE"; then
|
||||
echo "[x] Something went wrong!"
|
||||
rm -rf "$OUTFILE"
|
||||
else
|
||||
echo "[+] Saved the decrypted file to '$OUTFILE'"
|
||||
fi
|
||||
else
|
||||
# if payload file then encrypt with stdin
|
||||
echo -ne "$1" | openssl enc "-$ALGO" -a -A -d -pbkdf2 -pass pass:"$KEY"
|
||||
fi
|
||||
}
|
||||
Loading…
Reference in New Issue