-
Notifications
You must be signed in to change notification settings - Fork 0
/
encrypted_password.sh
executable file
·65 lines (45 loc) · 1.21 KB
/
encrypted_password.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
#!/bin/bash
#
# encrypt a password with openssl command
#
# usage:
# $0 [-v]
#
# -v - debug/verbose mode
#
args="$@"
debug=0
for arg in ${args[@]}; do
[[ $arg == "-v" ]] && debug=1
done
fail() {
echo "ERROR: $*" && exit 1
}
info() {
[[ $debug -eq 1 ]] && echo "[+] $*"
}
passfile=._tmp
encpassfile=pass.enc
#############################
## READ PASSWORD FROM USER ##
echo -n "input password to encrypt: "
read pass1
echo -n "confirm password: "
read pass2
[[ "$pass1" == "$pass2" ]] || fail "passwords do not equal"
echo "$pass1" > $passfile
#############################
##########################
## ENCRYPT THE PASSWORD ##
info "executing... openssl enc -aes256 -pbkdf2 -salt -in PASSFILE -out $encpassfile"
# TODO: add possibility to change the arguments
openssl enc -aes256 -pbkdf2 -salt -in $passfile -out $encpassfile || fail "failed to encrypt your password. refer to this ($0) script."
##########################
##############
## FINALIZE ##
# remove process remnants
rm $passfile
info "successfully created encrypted password"
info "to decrypt the password: 'openssl enc -aes256 -pbkdf2 -salt -d -in $encpassfile'"
echo -e "\nYou may locate your encrypted file in '$encpassfile'"
exit 0