3 * @author Jan Altensen (Stricted)
4 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
5 * @copyright 2015-2016 Jan Altensen (Stricted)
9 * sends the encrypted request to router
12 * @param mixed $fields
13 * @param string $cookie
16 private function sendEncryptedRequest ($path, $fields, $cookie = false) {
17 $count = count($fields);
18 $fields = $this->encrypt(http_build_query($fields));
19 return $this->sendRequest($path, $fields, $cookie, $count);
23 * decrypt data from router
28 private function decrypt ($data) {
29 $iv = hex2bin(substr($this->challenge
, 16, 16));
30 $adata = hex2bin(substr($this->challenge
, 32, 16));
31 $key = hex2bin($this->derivedk
);
32 $enc = hex2bin($data);
34 if (PHP_VERSION_ID
>= 70100) {
35 $ciphertext = substr($enc, 0, -8);
36 $tag = substr($enc, strlen($enc)-8);
38 return openssl_decrypt($ciphertext, 'aes-128-ccm', $key, OPENSSL_RAW_DATA
, $iv, $tag, $adata);
41 $factory = new CryptLib\Cipher\
Factory();
42 $aes = $factory->getBlockCipher('rijndael-128');
44 $mode = $factory->getMode('ccm', $aes, $iv, [ 'adata' => $adata, 'lSize' => 7]);
47 return $mode->finish();
52 * decrypt data for the router
57 private function encrypt ($data) {
58 $iv = hex2bin(substr($this->challenge
, 16, 16));
59 $adata = hex2bin(substr($this->challenge
, 32, 16));
60 $key = hex2bin($this->derivedk
);
66 if (PHP_VERSION_ID
>= 70100) {
68 $encdata = openssl_encrypt($data, 'aes-128-ccm', $key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING
, $iv, $tag, $adata, 8);
70 return bin2hex($encdata . $tag);
73 $factory = new CryptLib\Cipher\
Factory();
74 $aes = $factory->getBlockCipher('rijndael-128');
76 $mode = $factory->getMode('ccm', $aes, $iv, [ 'adata' => $adata, 'lSize' => 7]);
77 $mode->encrypt($data);
79 return bin2hex($mode->finish());