<?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["pubdec"]))
	{
		$data = $_POST["enc"];
		if(strlen($data) <= 0)
		{
			echo "WARNING : no input data<br/>";
			exit();
		}
		$enc = base64dec($data);
		$certfile=$_POST["cert"];
		if(strlen($certfile) <= 0)
		{
			echo "WARNING : no input data<br/>";
			exit();
		}
		$fp = fopen($certfile,"rb");
        	if($fp == NULL)
        	{
                	echo "open file error<br/>";
                	exit();
        	}

        	fseek($fp,0,SEEK_END);
        	$filelen=ftell($fp);
        	fseek($fp,0,SEEK_SET);
        	$cert = fread($fp,$filelen);
        	fclose($fp);
		
		$pubdec = publicDecryptCert(current($enc),$cert);
	
		#echo $pubdec,"<br/>";
		echo "source data : ",current($pubdec),"<br/>";
		echo "source data len: ",next($pubdec),"<br/>";
	}
	exit();
?>

