-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcryptography.sh
More file actions
executable file
·70 lines (58 loc) · 1.2 KB
/
cryptography.sh
File metadata and controls
executable file
·70 lines (58 loc) · 1.2 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
61
62
63
64
65
66
67
68
69
#!/bin/bash
function generate_random_key() {
local exec_result=$(python3 -c "
from p100 import encdec as crypto
key = crypto.generate_key()
print( key )
")
echo "$exec_result"
}
function encrypt() {
local exec_result=$(python3 -c "
from p100 import encdec as crypto
key = crypto.encrypt_value('$1', '$2')
print( key )
")
echo "$exec_result"
}
function decrypt() {
local exec_result=$(python3 -c "
from p100 import encdec as crypto
key = crypto.decrypt_value('$1','$2')
print( key )
")
echo "$exec_result"
}
function usage() {
echo "Usage: $0 [action] [parameters]"
echo "Usage: $0 generate_key"
echo "Usage: $0 encrypt key text_to_be_encrypted"
echo "Usage: $0 decrypt key text_to_be_decrypted"
}
if [[ ( "$#" -ne 1 ) && ( "$#" -ne 3 ) ]]; then
usage
exit 1;
fi
if [[ ( "$#" -eq 1) ]]; then
if [[ "$1" == "generate_key" ]]; then
exec_result=$(generate_random_key)
echo "$exec_result"
exit 0;
fi
usage
exit 1;
fi
if [[ ( "$#" -eq 3) ]]; then
if [[ "$1" != "encrypt" && "$1" != "decrypt" ]]; then
usage;
exit 1;
fi
fi
if [[ ( "$1" == "encrypt" ) ]]; then
encrypt "$2" "$3"
exit 0
fi
if [[ ( "$1" == "decrypt" ) ]]; then
decrypt "$2" "$3"
exit 0
fi