-
Notifications
You must be signed in to change notification settings - Fork 2
/
auth_aes_dec.sh
executable file
·59 lines (42 loc) · 1.25 KB
/
auth_aes_dec.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
#!/bin/bash
#
# Decrypt a block of data using a secret symmetric key that requires Authorization
#
set -u # stop if any variable is undefined
#set -e # stop if any command fails
############################################
# Check parameters
############################################
if [ $# -ne 3 ]
then
echo "Decrypt a block of data using a secret symmetric key that requires Authorization"
echo "Usage $0 <SecretId> <AuthId> <data>"
echo "Where:"
echo " <SecretId> is the secret AES key Id"
echo " <AuthId> is the authorization key Id"
echo " <data> is 16 hex bytes"
echo "Ex.: $0 12 13 00000000000000000000000000000000"
echo
echo "This script prompts for a password."
echo "The authorization key value must be equal to the SHA256 of this password."
exit 1
fi
SECRET_AES_KEY_ID=$1
AUTHORIZATION_KEY_ID=$2
DATA=$3
IV=00000000000000000000000000000000
read -s -p "Password: " pass
shapass=`echo -n "$pass" | sha256sum | cut -d' ' -f 1`
./authorize.sh $AUTHORIZATION_KEY_ID $shapass > /dev/null
if [ $? -ne 0 ]
then
echo
echo "Authentication failure."
exit 1
else
echo "Ok"
fi
set -e
./load_tempkey $IV > /dev/null
./gendig $SECRET_AES_KEY_ID > /dev/null
./aes_decrypt TEMPKEY $DATA