Skip to content

Instantly share code, notes, and snippets.

@the-cc-dev
Forked from NullArray/demo_encrypt_decrypt.sh
Created April 8, 2020 00:34
Show Gist options
  • Save the-cc-dev/99d6c9aae6077964c4240e55eff51527 to your computer and use it in GitHub Desktop.
Save the-cc-dev/99d6c9aae6077964c4240e55eff51527 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