-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakeKeyPair
executable file
·51 lines (47 loc) · 1.37 KB
/
makeKeyPair
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
KEY_NAME="demoKey"
KEY_LENGTH=4096
KEY_VALID_LENGTH=1
# Use > 0 to consume one or more arguments per pass in the loop
while [[ $# > 0 ]]
do
key="$1"
case $key in
-n|--keyname)
KEY_NAME="$2"
shift # past argument
;;
-k|--keylength)
KEY_LENGTH="$2"
shift # past argument
;;
-v|--validlength)
KEY_VALID_LENGTH="$2"
shift # past argument
;;
-h|--help|-?)
echo ""
echo "makekeypair creates a directory and fills it with "
echo "the desired key pair files."
echo ""
echo "Example execution:"
echo " makekeypair -n demokey -k 2048 -v 1w"
echo ""
echo "arguments:"
echo " -n, --keyname | The name of the key"
echo " -k, --keylength | The length of the key"
echo " -v, --validlength | The valid length of the key"
echo ""
shift # past argument
exit 1
;;
esac
shift # past argument or value
done
NAME=${KEY_NAME}_${KEY_LENGTH}
mkdir ${NAME}
cd ${NAME}
openssl genrsa -out ${NAME}.key ${KEY_LENGTH}
openssl req -new -key ${NAME}.key -out ${NAME}.csr -subj "/C=US/ST=Texas/L=Austin/O=UnboundID/OU=UnboundID/CN=localhost/[email protected]/serialNumber=0123456/" -nodes
openssl x509 -req -days ${KEY_VALID_LENGTH} -in ${NAME}.csr -signkey ${NAME}.key -out ${NAME}.crt
openssl pkcs8 -topk8 -inform PEM -outform PEM -in ${NAME}.key -out ${NAME}.pem -nocrypt