Skip to content

Instantly share code, notes, and snippets.

@NullArray
Forked from idodeclare/demo_encrypt_decrypt.sh
Created December 31, 2019 20:44
Show Gist options
  • Save NullArray/9e67ddb5964cd20ab174090b791c9224 to your computer and use it in GitHub Desktop.
Save NullArray/9e67ddb5964cd20ab174090b791c9224 to your computer and use it in GitHub Desktop.
#!/bin/sh
keylength=8
algo=$1
[[ "$algo" = "aes" ]] && keylength=16
[[ "$algo" = "3des" ]] && keylength=24
encfile=$(mktemp -t _encXXXXXX) && \
keyfile=$(mktemp -t _encXXXXXX) && \
dd if=/dev/urandom of="$keyfile" bs="$keylength" count=1 >/dev/null 2>&1 && \
encrypt -a "$algo" -k "$keyfile" -i /etc/resolv.conf -o "$encfile" && \
decrypt -a "$algo" -k "$keyfile" -i "$encfile"
rc=$?
rm "$encfile" "$keyfile"
exit $rc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment