Last active
August 29, 2015 14:07
-
-
Save iconara/184934a77d1c7c032fa3 to your computer and use it in GitHub Desktop.
Encrypt and decrypt strings with your SSH key
This file contains hidden or 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/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