<html>
	<body>
		<h1>FORM DATA</h1>
		<form action="" method="post">
			ID Client : <input type="text" name="id_client"> <br>
			KEY : <input type="text" name="key"> <br>
			NPM : <input type="text" name="npm"> <br>
			<input type="submit" value="Kirim">
		</form>

	</body>
</html>

<?php
if(!empty($_POST))
                {
//echo "<pre>";
                        echo '<hr><h1>HASIL</h1>';
                        //print_r($_POST);
                        //echo "<br>";

echo "<h3>SEBELUM KIRIM KE SERVER</h3>";
$data = array(
			'id_client' => $_POST['id_client'],
			'type' => 'GET_MHS',
			'npm' => $_POST['npm']
			);

		$encypt = $this->unilasecure->encrypt_client_arr($data, $_POST['key']);
echo "<b>Plain Teks</b><br>";
$dd = new Obj();
$dd->id_client = $_POST['id_client'];
$dd->data = $data;
echo "<pre>";
echo json_encode($dd, JSON_PRETTY_PRINT);
echo "</pre>";

echo "<br><b>Hasil Enkripsi</b><br>";
$dd->data = $encypt;
echo "<pre>";
echo json_encode($dd, JSON_PRETTY_PRINT);
//echo "<p>$encypt</p>";
echo "</pre>";

echo "<hr><h3>RESPON SERVER</h3>";

                        $options = [
                                CURLOPT_CUSTOMREQUEST => 'POST',
                                CURLOPT_RETURNTRANSFER => 1,
                                CURLOPT_POST => 1,
                                CURLOPT_URL => 'https://uptbahasa.unila.ac.id/api/Server/get_mhs_npm',
                                CURLOPT_POSTFIELDS => 'id_client='.$_POST['id_client'].'&data='.$encypt.'&key='.$_POST['key']

                        ];
                         
                        $ch = curl_init();
                        curl_setopt_array($ch, $options);
                        $content = curl_exec($ch);
                        curl_close($ch);
			
$id_server = "serverSimponilaDummy";
                	$key_server = "cThIIoDvwdueQB468K5xDc5633seEFoqwxjF_xSJyQQ";
			$dt = new Obj();
			$dt->id_server = $id_server;
			$dt->data = $content;

echo "<b>Terenkripsi</b>";
echo "<pre>";
echo json_encode($dt, JSON_PRETTY_PRINT);
echo "</pre>";

			//echo "<p>".$content."</p>";

			//echo "<h3>DEKRIPSI <i>(Unila Secure)</i> PADA CLIENT</h3>";

			$decypt = $this->unilasecure->decrypt_client_arr($content, $key_server);
			;

$dt->data = $decypt;

echo "<b>Hasil Dekripsi pada Client</b>";
echo "<pre>";
echo json_encode($dt, JSON_PRETTY_PRINT);
echo "</pre>";
			//echo json_encode($dt, JSON_PRETTY_PRINT);

                        //print_r(json_decode($content));
                }

class Obj {};
