-
Notifications
You must be signed in to change notification settings - Fork 0
/
nyx.sh
executable file
·100 lines (79 loc) · 2.54 KB
/
nyx.sh
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
#!/usr/bin/env bash
#
# Author: FlareXes
# License: Unlicense
# Original Script: https://github.com/FlareXes/Micro-Utils/blob/main/bin/nyx.sh
encrypt_file() {
local file_path="$1"
# Prompt for password to encrypt with 7z
read -s -p "Enter password for 7z encryption: " password_7z
echo
# Encrypt with 7z (using AES-256 encryption)
echo "Encrypting with 7z..."
7z a -p"${password_7z}" -mhe=on "${file_path}.7z" "${file_path}"
# Check if 7z encryption was successful
if [ $? -ne 0 ]; then
echo "7z encryption failed."
exit 1
fi
# Prompt for password to encrypt with openssl
read -s -p "Enter password for openssl encryption: " password_openssl
echo
# Encrypt with openssl (using AES-256-CBC encryption)
echo "Encrypting with openssl..."
openssl enc -aes-256-cbc -salt -pbkdf2 -iter 2000000 -md sha512 -base64 -in "${file_path}.7z" -out "${file_path}.7z.enc" -pass pass:"${password_openssl}"
# Check if openssl encryption was successful
if [ $? -ne 0 ]; then
echo "openssl encryption failed."
exit 1
fi
echo "File successfully double encrypted: ${file_path}.7z.enc"
}
decrypt_file() {
local encrypted_file="$1"
# Prompt for password to decrypt with openssl
read -s -p "Enter password for openssl decryption: " password_openssl
echo
# Decrypt with openssl
echo "Decrypting with openssl..."
openssl enc -d -aes-256-cbc -pbkdf2 -iter 2000000 -md sha512 -base64 -in "${encrypted_file}" -out "${encrypted_file%.enc}" -pass pass:"${password_openssl}"
# Check if openssl decryption was successful
if [ $? -ne 0 ]; then
echo "openssl decryption failed."
exit 1
fi
# Prompt for password to decrypt with 7z
read -s -p "Enter password for 7z decryption: " password_7z
echo
# Extract with 7z
echo "Extracting with 7z..."
7z x -p"${password_7z}" "${encrypted_file%.enc}"
# Check if 7z extraction was successful
if [ $? -ne 0 ]; then
echo "7z extraction failed."
exit 1
fi
echo "File successfully decrypted: ${encrypted_file%.enc}"
}
# Check if the script is called with arguments
if [ "$#" -ne 2 ]; then
echo "Usage:"
echo "Encrypt: $0 encrypt <file_path>"
echo "Decrypt: $0 decrypt <encrypted_file>"
exit 1
fi
mode="$1"
file="$2"
case "$mode" in
encrypt)
encrypt_file "${file}"
;;
decrypt)
decrypt_file "${file}"
;;
*)
echo "Invalid mode. Use 'encrypt' or 'decrypt'."
exit 1
;;
esac
exit 0