<?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["pubenc"]))
	{
		$data = $_POST["plaint"];
		if(strlen($data) <= 0)
		{
			echo "WARNING : no input data<br/>";
			exit();
		}
		
		$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);
		
		$pubenc = publicEncryptCert($data,$cert);
	
		#echo base64enc($pubenc),"<br/>";
		echo "public encryption : ",current(base64enc(current($pubenc))),"<br/>";
		echo "public encryption len: ",next($pubenc),"<br/>";
	}
	exit();
?>

