Created
November 20, 2014 14:55
-
-
Save maggiben/2c7e827245aa014055c7 to your computer and use it in GitHub Desktop.
openssl use ssh keys to crypt & decrypt strings (plain strings no files)
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
encrypt() { | |
PUBLIC_KEY="~/.ssh/id_rsa" | |
echo $1 | openssl rsautl -encrypt -inkey <(openssl rsa -in ~/.ssh/id_rsa -outform pem 2> /dev/null | openssl rsa -pubout 2> /dev/null) -pubin | openssl base64 | |
} | |
decrypt() { | |
PUBLIC_KEY="~/.ssh/id_rsa" | |
echo "$1" | openssl base64 -d | openssl rsautl -decrypt -inkey <(openssl rsa -in ~/.ssh/id_rsa -outform pem 2> /dev/null) | |
} | |
NOOK=$(encrypt "Hello world") | |
KOON=$(decrypt "$NOOK") | |
echo "crypt: " $NOOK | |
echo "decry: " $KOON |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment