-
Notifications
You must be signed in to change notification settings - Fork 0
/
decryption.php
200 lines (145 loc) · 5.84 KB
/
decryption.php
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<?php
session_start();
//Initialisating Session Variables
$_SESSION['message'] = "";
//Initialising Variables
$semail = "";
$msgsub = "";
$enmsg = "";
$dekey = "";
$cipher = "";
$method = "";
$message = "";
//Create Connection
$conn = mysqli_connect("localhost","root","","message_transfer");
//Check Connection
if (!$conn){
die("Connection Failed: " . mysqli_connect_error());
}
//Checking if fields are empty or not
if(isset($_POST['decrypt'])){
if(empty($_POST['semail']) || empty($_POST['msgsub']) || empty($_POST['enmsg']) || empty($_POST['dekey'])){
echo '<script>alert("Please enter all the fields")</script>';
}
else{
//Fetch data from the form and store in the variables
$semail = mysqli_real_escape_string($conn, $_POST['semail']);
$msgsub = mysqli_real_escape_string($conn, $_POST['msgsub']);
$enmsg = mysqli_real_escape_string($conn, $_POST['enmsg']);
$dekey = mysqli_real_escape_string($conn, $_POST['dekey']);
$user_check_query = "SELECT * FROM users WHERE email = '$semail'";
$data_check_query = "SELECT * FROM data_store WHERE msgsub = '$msgsub' and cipher_key = '$dekey'";
$result1 = mysqli_query($conn, $user_check_query);
$result2 = mysqli_query($conn, $data_check_query);
$mail = mysqli_fetch_assoc($result1);
$data = mysqli_fetch_assoc($result2);
//if($mail['email'] === $remail){
if($data['msgsub'] == $msgsub and $data['cipher_key'] == $dekey){
if($enmsg == $_SESSION['enmsg']){
$cipher = $data['cipher'];
}
}
//}
//Providing a initialising vector
$de_iv = "1029199712021998";
$options = 0;
//Decryption using RC4
if($cipher == 1){
$method = "RC4";
$iv_length = openssl_cipher_iv_length($method);
$message = openssl_decrypt($enmsg, $method, $dekey, $options);
echo '<script>alert("Recieved Successfully.")</script>';
}
//Encryption using AES-128-CBC
if($cipher == 2){
$method = "AES-128-CBC";
$iv_length = openssl_cipher_iv_length($method);
$message = openssl_decrypt($enmsg, $method, $dekey, $options, $de_iv);
echo '<script>alert("Recieved Successfully.")</script>';
}
//Encryption using AES-192-CBC
if($cipher == 3){
$method = "AES-192-CBC";
$iv_length = openssl_cipher_iv_length($method);
$message = openssl_decrypt($enmsg, $method, $dekey, $options, $de_iv);
echo '<script>alert("Recieved Successfully.")</script>';
}
//Encryption using AES-256-CBC
if($cipher == 4){
$method = "AES-256-CBC";
$iv_length = openssl_cipher_iv_length($method);
$message = openssl_decrypt($enmsg, $method, $dekey, $options, $de_iv);
echo '<script>alert("Recieved Successfully.")</script>';
}
}
$_SESSION['message'] = $message;
echo '<script>alert("Recieved Successfully.")</script>';
header('location: recievedmsg.php');
}
else{
if(isset($_POST['back'])){
header('location: dashboard.php');
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!--Import Google Icon Font-->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!-- Compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<!--Import Custom CSS-->
<link rel="stylesheet" href="/styles/style.css">
<!-- Compiled and minified jQuery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- Compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
<title>Decrypt Here</title>
</head>
<body>
<div class="container">
<div class="setting">
<div class="row">
<form class="col s11" method="POST">
<div class="row">
<div class="input-field">
<i class="material-icons prefix">email</i>
<input id="semail" type="email" class="validate" name="semail">
<label for="semail">Recieved From</label>
</div>
</div>
<div class="row">
<div class="input-field">
<i class="material-icons prefix">subject</i>
<input id="msgsub" type="text" name="msgsub">
<label for="msgsub">Subject</label>
</div>
</div>
<div class="row">
<div class="input-field">
<i class="material-icons prefix">message</i>
<textarea id="enmsg" class="materialize-textarea" name="enmsg"></textarea>
<label for="enmsg">Recieved Message</label>
</div>
</div>
<!-- the user only gets the option to decrypt. no knowledge of encryption algorithm to be provided -->
<div class="row">
<div class="input-field">
<i class="material-icons prefix">vpn_key</i>
<input id="dekey" type="text" name="dekey">
<label for="dekey">Decryption Key</label>
</div>
</div>
<div class="center-align">
<button class="btn waves-effect waves-light" type="submit" name="decrypt">Decrypt</button>
<button class="btn waves-effect waves-light" type="submit" name="back">Back to Dashboard</button>
</div>
</form>
</div>
</div>
</div>
</body>
</html>