<?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["prienc"]))
	{
		$plaint=$_POST["plaint"];
		if(strlen($plaint) <= 0)
		{
			echo "WARNING : no source data input<br/>";
			exit();
		}
		$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();
              	}
		$prienc = privateEncryptPwd($plaint,$key,$pass);
		#echo base64enc($prienc),"<br/>";
		$code = current($prienc);
		$len = next($prienc);
		$enccode = base64enc($code);
		echo "private encryption : ",current($enccode),"<br/>";
		echo "private encryption len: ",$len,"<br/>";
	}
	exit();
?>

