-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdecrypt-research.sh
More file actions
executable file
·60 lines (49 loc) · 1.61 KB
/
Copy pathdecrypt-research.sh
File metadata and controls
executable file
·60 lines (49 loc) · 1.61 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
#!/usr/bin/env bash
# Decrypts all .enc files in docs/research/ back to plaintext.
# Verifies the entered password matches the hash stored in .research.hash.
set -euo pipefail
REPO_ROOT="$(git -C "$(dirname "$0")" rev-parse --show-toplevel)"
RESEARCH_DIR="$REPO_ROOT/docs/research"
if [ ! -d "$RESEARCH_DIR" ]; then
echo "decrypt-research: research dir not found." >&2
exit 1
fi
ENC_FILES=()
while IFS= read -r -d '' f; do
ENC_FILES+=("$f")
done < <(find "$RESEARCH_DIR" -type f -name "*.enc" -print0)
if [ ${#ENC_FILES[@]} -eq 0 ]; then
echo "No encrypted files found in docs/research/." >&2
exit 0
fi
# Verify hash file exists
HASH_FILE="$REPO_ROOT/.research.hash"
if [ ! -f "$HASH_FILE" ]; then
echo "ERROR: No password hash found. Run ./scripts/setup-encryption.sh first." >&2
exit 1
fi
STORED_HASH="$(cat "$HASH_FILE")"
read -rsp "Enter decryption password: " PASSWORD </dev/tty
echo
if [ -z "$PASSWORD" ]; then
echo "ERROR: Password cannot be empty." >&2
exit 1
fi
# Verify password matches stored hash
ENTERED_HASH="$(printf '%s' "$PASSWORD" | shasum -a 256 | awk '{print $1}')"
if [ "$ENTERED_HASH" != "$STORED_HASH" ]; then
echo "ERROR: Incorrect password." >&2
exit 1
fi
for ENC_FILE in "${ENC_FILES[@]}"; do
OUT_FILE="${ENC_FILE%.enc}"
if openssl enc -d -aes-256-cbc -pbkdf2 -iter 100000 \
-in "$ENC_FILE" -out "$OUT_FILE" -pass "pass:$PASSWORD" 2>/dev/null; then
echo " decrypted: ${OUT_FILE#$REPO_ROOT/}"
else
echo "ERROR: Failed to decrypt ${ENC_FILE#$REPO_ROOT/} — wrong password or corrupted file." >&2
rm -f "$OUT_FILE"
exit 1
fi
done
echo "✅ Decryption complete."