Created
August 26, 2010 21:22
-
-
Save lauriro/552283 to your computer and use it in GitHub Desktop.
RSA Encryption
This file contains 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/sh | |
# openssl rsa -in ~/.ssh/id_rsa -pubout -out ~/.ssh/id_rsa.pub.pem | |
# ln -s ~/rsacrypt.sh /usr/bin/rsacrypt | |
ENCRYPTED="" | |
DECRYPTED="" | |
usage() { | |
echo -e "\nUsage: $0 [-e [PUBLIC_KEY]] [-d [PRIVATE_KEY]]" | |
exit 1 | |
} | |
while getopts ":d:e:" opt; do | |
[ "$OPTARG$opt" == "d:" ] && opt="d" && OPTARG=~/.ssh/id_rsa | |
[ "$OPTARG$opt" == "e:" ] && opt="e" && OPTARG=~/.ssh/id_rsa.pub.pem | |
case $opt in | |
e) | |
if [ -z "$DECRYPTED" ]; then | |
echo -e "\nEnter your decrypted content (end with ESC): " | |
read -d $(echo -e "\e") DECRYPTED | |
echo -e "\n" | |
fi | |
echo -e "\nEncrypted data for ${OPTARG##*/}:\n" | |
echo "$DECRYPTED" | openssl rsautl -inkey $OPTARG -pubin -encrypt | openssl base64 | |
;; | |
d) | |
if [ -z "$ENCRYPTED" ]; then | |
echo -e "\nEnter your encrypted content (end with ESC): " | |
read -d $(echo -e "\e") ENCRYPTED | |
echo -e "\n" | |
fi | |
DECRYPTED=$(echo "$ENCRYPTED" | openssl base64 -d | openssl rsautl -inkey $OPTARG -decrypt) | |
echo -e "\nDecrypted with ${OPTARG##*/}:\n$DECRYPTED" | |
;; | |
f) | |
#if [ -n "$DECRYPTED" ] | |
esac | |
done | |
[ -z "$ENCRYPTED$DECRYPTED" ] && usage |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment