-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeygen.sh
More file actions
executable file
·26 lines (21 loc) · 792 Bytes
/
Copy pathkeygen.sh
File metadata and controls
executable file
·26 lines (21 loc) · 792 Bytes
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
#!/bin/bash
if ! command -v openssl &> /dev/null; then
echo "OpenSSL is not installed" >&2
exit 1
fi
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
readonly OUTPUT_DIR="${1:-$SCRIPT_DIR/.secrets/keys}"
readonly PRIVATE_KEY_DIR="$OUTPUT_DIR/app.key"
readonly PUBLIC_KEY_DIR="$OUTPUT_DIR/app.pub"
openssl genpkey -algorithm RSA -out "$PRIVATE_KEY_DIR" -pkeyopt rsa_keygen_bits:2048 &> /dev/null
if [ ! -f "$PRIVATE_KEY_DIR" ]; then
echo "Error generating the private key" >&2
exit 1
fi
openssl rsa -pubout -in "$PRIVATE_KEY_DIR" -out "$PUBLIC_KEY_DIR" &> /dev/null
if [ ! -f "$PUBLIC_KEY_DIR" ]; then
echo "Error generating the public key" >&2
exit 1
fi
chmod 644 "$PRIVATE_KEY_DIR" "$PUBLIC_KEY_DIR" &> /dev/null
echo "RSA Keys generated successfully"