-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-pki-keys.sh
More file actions
executable file
·100 lines (86 loc) · 3 KB
/
create-pki-keys.sh
File metadata and controls
executable file
·100 lines (86 loc) · 3 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env bash
# Description: this is a script to create private and public encryption keys.
# function genPrivKey
genPrivKey()
{
read -p "Provide file name for private key: (should end in .pem) " KEYNAME;
echo ""
read -p "Provide the keylength: (512-2048) " KEYLENGTH;
echo ""
if [[ "${KEYNAME}" ]]
then
openssl genrsa -out "$KEYNAME" "$KEYLENGTH"
else
echo "Error generating private key" 2>&1;
exit 1;
fi
}
# function genPubKey
genPubKey()
{
# prompt user input
read -p "Provided the private key: " KEYNAME0;
echo ""
read -p "Provide file name for the public key: (should end in .pem) " KEYNAME1;
echo ""
if [[ "${KEYNAME0}" && "${KEYNAME1}" ]]
then
openssl rsa -in "${KEYNAME0}" -out "${KEYNAME1}" -outform PEM -pubout
else
echo "Error extracting public key from private key" 2>&1
exit 1
fi
}
# prompt for user input
read -p "Do you want to create a private key? (y/n): " ANSWER
# if statement to check value of the ANSWER variable
if [[ "${ANSWER}" = 'y' ]]
then
# call function
genPrivKey;
elif [[ "${ANSWER}" = 'n' ]]
then
# exit script
exit 0;
else
# display message
echo "please enter either y or n";
fi
# prompt user input
read -p "Do you want to generate a public key from a private key? (y/n)?" ANSWER1;
# if statement to check for variable ANSWER1
if [[ "${ANSWER1}" = 'y' ]]
then
# call function
genPubkey;
elif [[ "${ANSWER1}" = 'n' ]]
then
# exit script
exit 0;
else
# display mesage
echo "Please enter either y or n";
fi
##########################################################
#############
# my banner #
#############
##########################################################
# source: http://patorjk.com/software/taag/ #
##########################################################
echo -e "\nScripted by: ";
echo -e "\n";
echo -e "\033[0;5m";
echo " ██▓ ██████▄▄▄█████▓▄▄▄ ▄████▄ ██ ▄█▒███████▒";
echo "▓██▒██ ▒▓ ██▒ ▓▒████▄ ▒██▀ ▀█ ██▄█▒▒ ▒ ▒ ▄▀░";
echo "▒██░ ▓██▄ ▒ ▓██░ ▒▒██ ▀█▄ ▒▓█ ▄▓███▄░░ ▒ ▄▀▒░ ";
echo "░██░ ▒ ██░ ▓██▓ ░░██▄▄▄▄██▒▓▓▄ ▄██▓██ █▄ ▄▀▒ ░";
echo "░██▒██████▒▒ ▒██▒ ░ ▓█ ▓██▒ ▓███▀ ▒██▒ █▒███████▒";
echo "░▓ ▒ ▒▓▒ ▒ ░ ▒ ░░ ▒▒ ▓▒█░ ░▒ ▒ ▒ ▒▒ ▓░▒▒ ▓░▒░▒";
echo " ▒ ░ ░▒ ░ ░ ░ ▒ ▒▒ ░ ░ ▒ ░ ░▒ ▒░░▒ ▒ ░ ▒";
echo " ▒ ░ ░ ░ ░ ░ ▒ ░ ░ ░░ ░░ ░ ░ ░ ░";
echo " ░ ░ ░ ░ ░ ░ ░ ░ ░ ";
echo " ░ ░ ";
echo -e "\033[25m";
echo -e "\n";
###########################################################