-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaes.php
More file actions
61 lines (53 loc) · 1.4 KB
/
aes.php
File metadata and controls
61 lines (53 loc) · 1.4 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
<?php
class AES {
protected $key;
protected $data;
protected $method;
protected $options = 0;
function __construct($data = null, $key = null, $blockSize = null, $mode = 'CBC') {
$this->setData($data);
$this->setKey($key);
$this->setMethode($blockSize, $mode);
}
public function setData($data) {
$this->data = $data;
}
public function setKey($key) {
$this->key = $key;
}
public function setMethode($blockSize, $mode = 'CBC') {
if($blockSize == 192 && in_array('', array('CBC-HMAC-SHA1','CBC-HMAC-SHA256','XTS'))){
$this->method = null;
throw new Exception('Invlid block size and mode combination!');
}
$this->method = 'AES-' . $blockSize . '-' . $mode;
}
public function validateParams() {
if ($this->data != null
&& $this->method != null) {
return true;
} else {
return false;
}
}
protected function getIV() {
return '1234567890123456';
return openssl_random_pseudo_bytes(
openssl_cipher_iv_length($this->method));
}
public function decrypt() {
if ($this->validateParams()) {
return trim(
openssl_decrypt(
$this-> data,
$this-> method,
$this-> key,
$this-> options,
$this-> getIV() ));
} else {
throw new Exception('Invlid params!');
}
}
}
$aes = new AES($_GET["string"], $_GET["key"], $_GET["bits"]);
echo $aes->decrypt();