<?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["getpublickey"]))
	{
		$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);
		
		$pubkey = getPublicKey($cert);
		$key = current($pubkey);
		$len = next($pubkey);

		$keycode = base64enc($key);
		echo "public key : ",current($keycode),"<br/>";
		echo "public key len : ",$len,"<br/>";
	}
	exit();
?>

