forked from engly817chat/engly-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_keys.sh
More file actions
40 lines (30 loc) · 887 Bytes
/
generate_keys.sh
File metadata and controls
40 lines (30 loc) · 887 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash
set -e
CERT_DIR="src/main/resources/certs"
KEYPAIR="$CERT_DIR/keypair.pem"
PUBLIC_KEY="$CERT_DIR/publicKey.pem"
PRIVATE_KEY="$CERT_DIR/privateKey.pem"
missing=0
# Check existence
[[ -f "$KEYPAIR" ]] || missing=1
[[ -f "$PUBLIC_KEY" ]] || missing=1
[[ -f "$PRIVATE_KEY" ]] || missing=1
if [[ $missing -eq 0 ]]; then
echo "All key files already exist in $CERT_DIR."
exit 0
fi
echo "Generating RSA key files in $CERT_DIR ..."
mkdir -p "$CERT_DIR"
if [[ ! -f "$KEYPAIR" ]]; then
openssl genrsa -out "$KEYPAIR" 2048
echo "Generated $KEYPAIR"
fi
if [[ ! -f "$PUBLIC_KEY" ]]; then
openssl rsa -in "$KEYPAIR" -pubout -out "$PUBLIC_KEY"
echo "Generated $PUBLIC_KEY"
fi
if [[ ! -f "$PRIVATE_KEY" ]]; then
openssl pkcs8 -topk8 -inform PEM -outform PEM -nocrypt -in "$KEYPAIR" -out "$PRIVATE_KEY"
echo "Generated $PRIVATE_KEY"
fi
echo "Key generation complete."