-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncrypt-decrypt-tool.php
More file actions
138 lines (125 loc) · 4.41 KB
/
Encrypt-decrypt-tool.php
File metadata and controls
138 lines (125 loc) · 4.41 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
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
<?php
/*
Plugin Name: Encrypt Decrypt Tool
Plugin URI: http://eresdev.com/tools/encrypt-decrypt
Description: A wordpress plugin to add a tool to encrypt/decrypt
Version: 1.0
Author: EresDev
Author URI: http://eresdev.com
License: GPL2
*/
function encrypt_decrypt_tool_html(){
$error = false;
$msgs = array();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$method = intval($_POST['method']);
$key = $_POST['key'];
$key_confirm = $_POST['key_confirm'];
$main_text = $_POST['main_text'];
//check for errors
if(str_replace(' ', '', $key) == ""){
$error = true;
$msgs[] = "Key cannot be empty.";
}
if($key != $key_confirm){
$error = true;
$msgs[] = "Key and Confirm Key do not match.";
}
if(str_replace(' ', '', $main_text) == ""){
$error = true;
$msgs[] = "You have not provided text to encrypt/decrypt.";
}
if(!$error){
$ciphers = openssl_get_cipher_methods();
echo "<p>Find below your <b>".(isset($_POST['encrypt'])?"encrypted":"decrypted")."</b> text.";
echo "<pre>";
if (isset($_POST['encrypt'])) {
echo openssl_encrypt($main_text,$ciphers[$method],$key);
}
elseif (isset($_POST['decrypt'])) {
echo openssl_decrypt($main_text,$ciphers[$method],$key);
}
echo "</pre>";
echo "<p style='text-align:center;'><a href='".get_permalink()."'>Encrypt/Decrypt your text again.</a></p>";
}
}
if ($_SERVER['REQUEST_METHOD'] !== 'POST' || $error) {
if($error){
foreach($msgs as $msg){
echo "<p class='error'><b>ERROR:</b> $msg</p>";
}
}
?>
<form name="encrypt_decrypt_tool" method="post">
<label>Choose an encryption/decryption method:<br><select name="method" required>
<?php
$ciphers = openssl_get_cipher_methods();
foreach ($ciphers as $i => $cipher) { ?>
<option value="<?php echo $i; ?>" <?php echo $_REQUEST["method"]== $i?"selected":""; ?>>OpenSSL <?php echo $cipher; ?></option>
<?php } ?>
</select></label>
<label>Insert your key:<br>
<input type="password" name="key" id="key" required pattern=".*\S+.*"
title="This field is required"></label>
<label>Confirm your key:<br>
<input type="password" name="key_confirm" oninput="check(this)" required pattern=".*\S+.*"
title="This field is required"></label>
<label>Insert text to Encrypt/Decrypt:<br>
<textarea name="main_text" required pattern=".*\S+.*" title="This field is required"><?php echo $_REQUEST['main_text']; ?></textarea></label>
<div class="btn-container">
<input type="submit" name="encrypt" value="Encrypt">
<input type="submit" name="decrypt" value="Decrypt">
</div>
</form>
<?php
}
?>
<script type="text/javascript">
function check(input) {
if (input.value != document.getElementById('key').value) {
input.setCustomValidity('Confirm key must be matching to the key.');
} else {
// input is valid -- reset the error message
input.setCustomValidity('');
}
}
</script>
<style type="text/css">
label {
display: block;
}
p.post-date {
display: none;
}
select, input[type=password], textarea[name=main_text] {
width: 100%;
border: 1px solid #5d5d5d;
padding: 0 10px;
font-family: Arial;
border-radius: 0;
}
textarea[name=main_text] {
height: 300px;
font-family: Arial;
font-size: 12px;
}
input[type=submit] {
width: 40%;
}
div.btn-container {
text-align: center;
}
form {
margin-bottom: 100px;
}
p.error{
color: red;
}
pre{
background:#ccc;
padding: 10px;
}
</style>
<?php
}
add_shortcode("encrypt_decrypt_tool", "encrypt_decrypt_tool_html");