Last active
December 12, 2015 02:08
-
-
Save syusui-s/4696243 to your computer and use it in GitHub Desktop.
make key, encrypt, decrypt (openssl)
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
rand.dat | |
private.key | |
public.key |
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/bash | |
if [ $# -eq 0 ]; then | |
echo "Usage: decrypt INPUT OUTPUT" | |
exit 0 | |
fi | |
if [ $# -ge 3 ]; then | |
echo "error: too many args" | |
exit 1 | |
fi | |
if [ $# -eq 1 ]; then | |
export OUT=$1.out | |
else | |
export OUT=$2 | |
fi | |
echo "decrypting $1" | |
openssl rsautl -decrypt -inkey private.key -in $1 -out $OUT |
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/bash | |
if [ $# -eq 0 ]; then | |
echo "Usage: encrypt INPUT OUTPUT" | |
exit 0 | |
fi | |
if [ $# -ge 3 ]; then | |
echo "error: too many args" | |
exit 1 | |
fi | |
if [ $# -eq 1 ]; then | |
export OUT=$1.priv | |
else | |
export OUT=$2 | |
fi | |
echo "encripting $1" | |
openssl rsautl -encrypt -pubin -inkey public.key -in $1 -out $OUT |
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/bash | |
if [ $# -ge 2 ]; then | |
echo "error: too many args" | |
exit 1 | |
fi | |
if [ -z $1 ]; then | |
export BITS=512 | |
else | |
export BITS=$1 | |
fi | |
if echo $1 | grep help >> /dev/null ;then | |
echo "usage: ${0} <BITS>" | |
echo "BIT is a length of rsa key" | |
exit 0 | |
fi | |
if [ $BITS -le 30 ]; then | |
echo "error: key size is too small" | |
exit 1 | |
fi | |
openssl rand 4096 -out rand.dat && | |
openssl genrsa -rand rand.dat -out private.key $BITS && | |
openssl rsa -in private.key -pubout -out public.key && | |
rm rand.dat |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment