-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecrypt.php
73 lines (65 loc) · 2.2 KB
/
decrypt.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
<?php
require_once(__DIR__.'/header.php');
require_once(__DIR__.'/define.php');
require_once(__DIR__.'/EncryptionData.php');
if(isset($_GET['fileInput'])){
// $uploaddir = __DIR__.'/files/hash/';
// $file = $uploaddir . basename($uploaddir.$_GET['fileInput'].'.encrypt');
$uploaddir = __DIR__.'/files/hash/';
$uploadfile = $uploaddir . basename($_FILES['fileInput']['name']);
?>
<div class="col-sm-12">
<?php
if (move_uploaded_file($_FILES['fileInput']['tmp_name'], $uploadfile)) {
echo 'File is valid, and was successfully uploaded.';
} else {
echo "Possible file upload attack!\n";
die();
}
?>
</div>
<?php
if(file_exists($uploadfile)){
$decrypted_string = EncryptionData::mc_decrypt(file_get_contents($uploadfile), ENCRYPTION_KEY);
if($decrypted_string == -1){
echo 'iv size is different !';
}
if($decrypted_string == -2){
echo 'Hash mac is different !';
}
else {
echo 'Decrypted data:' .'<br>';
echo '<textarea class="form-control" rows="5">'.$decrypted_string.'</textarea>';
?>
<div class="col-sm-12">
<p></p>
<a class="btn btn-success" href="/download.php?file=<?= basename($_FILES['fileInput']['name']) ?>">Download data as file</a>
</div>
<?php
}
} else {
echo 'File doesn\'t exist';
}
} else {
?>
<div class="col-sm-12">
Please select file for decryption.
</div>
<div class="col-sm-12">
<form class="form form-horizontal" action="" method="post" enctype="multipart/form-data" style="margin-top: 30px;">
<div class="form-group">
<label class="control-label col-sm-2" id="file">File</label>
<div class="col-sm-8">
<input id="input-id" type="file" class="file" name="fileInput">
</div>
</div>
</form>
</div>
<script type="text/javascript">
$(document).ready(function(){
$("#input-id").fileinput();
});
</script>
<?php
}
require_once(__DIR__.'/footer.php');