3 * @author Jan Altensen (Stricted)
4 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
5 * @copyright 2015 Jan Altensen (Stricted)
9 * sends the encrypted request to router
12 * @param mixed $fields
13 * @param string $cookie
16 private function sentEncryptedRequest ($path, $fields, $cookie = false) {
17 $count = count($fields);
18 $fields = $this->encrypt(http_build_query($fields));
19 return $this->sentRequest($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 $factory = new CryptLib\Cipher\
Factory();
35 $aes = $factory->getBlockCipher('rijndael-128');
37 $mode = $factory->getMode('ccm', $aes, $iv, [ 'adata' => $adata, 'lSize' => 7]);
41 return $mode->finish();
45 * decrypt data for the router
50 private function encrypt ($data) {
51 $iv = hex2bin(substr($this->challenge
, 16, 16));
52 $adata = hex2bin(substr($this->challenge
, 32, 16));
53 $key = hex2bin($this->derivedk
);
55 $factory = new CryptLib\Cipher\
Factory();
56 $aes = $factory->getBlockCipher('rijndael-128');
58 $mode = $factory->getMode('ccm', $aes, $iv, [ 'adata' => $adata, 'lSize' => 7]);
59 $mode->encrypt($data);
61 return bin2hex($mode->finish());