+ /**
+ * decrypt data from router
+ *
+ * @param string $data
+ * @return array
+ */
+ public function decrypt ($data) {
+ require_once 'CryptLib/CryptLib.php';
+ $factory = new CryptLib\Cipher\Factory();
+ $aes = $factory->getBlockCipher('rijndael-128');
+
+ $iv = hex2bin(substr($this->challenge, 16, 16));
+ $adata = hex2bin(substr($this->challenge, 32, 16));
+ $dkey = hex2bin($this->derivedk);
+ $enc = hex2bin($data);
+
+ $aes->setKey($dkey);
+ $mode = $factory->getMode('ccm', $aes, $iv, [ 'adata' => $adata, 'lSize' => 7]);
+
+ $mode->decrypt($enc);
+
+ return $mode->finish();
+ }
+
+ /**
+ * decrypt data for the router
+ *
+ * @param array $data
+ * @return string
+ */
+ public function encrypt ($data) {
+ require_once 'CryptLib/CryptLib.php';
+ $factory = new CryptLib\Cipher\Factory();
+ $aes = $factory->getBlockCipher('rijndael-128');
+
+ $iv = hex2bin(substr($this->challenge, 16, 16));
+ $adata = hex2bin(substr($this->challenge, 32, 16));
+ $dkey = hex2bin($this->derivedk);
+
+ $aes->setKey($dkey);
+ $mode = $factory->getMode('ccm', $aes, $iv, [ 'adata' => $adata, 'lSize' => 7]);
+ $mode->encrypt(http_build_query($data));
+
+ return bin2hex($mode->finish());
+ }
+