Skip to content

Instantly share code, notes, and snippets.

@iconara
Last active August 29, 2015 14:07
Show Gist options
  • Save iconara/184934a77d1c7c032fa3 to your computer and use it in GitHub Desktop.
Save iconara/184934a77d1c7c032fa3 to your computer and use it in GitHub Desktop.
Encrypt and decrypt strings with your SSH key
#!/bin/bash
case $1 in
encrypt)
pem_path=/tmp/$(basename $1).pem
ssh-keygen -f $2 -e -m PKCS8 > $pem_path
openssl rsautl -encrypt -pubin -inkey $pem_path -ssl | base64
srm $pem_path
;;
decrypt)
cat | base64 --decode | openssl rsautl -decrypt -inkey $2
;;
*)
cmd=$(basename $0)
echo "Usage: $cmd [command] [key path]
Reads from stdin and writes to stdout
Commands:
encrypt path-to-id_rsa.pub
decrypt path-to-id_rsa
" 1>&2
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment