Skip to content

Instantly share code, notes, and snippets.

@syusui-s
Last active December 12, 2015 02:08
Show Gist options
  • Save syusui-s/4696243 to your computer and use it in GitHub Desktop.
Save syusui-s/4696243 to your computer and use it in GitHub Desktop.
make key, encrypt, decrypt (openssl)
rand.dat
private.key
public.key
#!/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
#!/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
#!/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