<?php
	if (!extension_loaded('infosec'))
	{
		if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
  		{
			dl('php_infosec.dll');
		}
   		else
		{
			dl('infosec.so');
		}
 	}
	else
	{
		echo "loaded infosec module success <br/>";
	}

	if(isset($_POST["pridec"]))
	{
		$enc=$_POST["enc"];
		if(strlen($enc) <= 0)
		{
			echo "WARNING : no source data input<br/>";
			exit();
		}
		$data = base64dec($enc);
		$keyfile=$_POST["key"];
		if(strlen($keyfile) <= 0)
              	{
              		echo "WARNING : no key data input<br/>";
			exit();
              	}
		//read private key from file
        	$fp = fopen($keyfile,"rb");
        	if($fp == NULL)
        	{
                	echo "open file error<br/>";
                	exit();
        	}

        	fseek($fp,0,SEEK_END);
        	$filelen=ftell($fp);
        	fseek($fp,0,SEEK_SET);
        	$contents = fread($fp,$filelen);
		fclose($fp);
		$key = substr($contents,2);

		$pass=$_POST["pass"];
              	if(strlen($pass) <= 0)
              	{
              		echo "WARNING : no key password input<br/>";
			exit();
              	}
		$pridec = privateDecryptPwd(current($data),$key,$pass);
		#echo $pridec,"<br/>";
		echo "source data : ",current($pridec),"<br/>";
		echo "source data len: ",next($pridec),"<br/>";
	}
	exit();
?>


