<?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["verifysign"]))
        {
		$plaint=$_POST["plaint"];
              	if(strlen($plaint) <= 0)
              	{
              		echo "WARNING : no source data input<br/>";
			exit();
              	}
              	$certfile=$_POST["cert"];
              	if(strlen($certfile) <= 0)
              	{
              		echo "WARNING : no cert file input<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);

		$signdata=$_POST["sign"];
              if(strlen($signdata) <= 0)
              {
              	echo "WARNING : no signature input<br/>";
			exit();
              }
		$sign = base64dec($signdata);
              $rv = verifySign($plaint,$cert,current($sign));
              if($rv)
		{
			echo "verify error!<br/>";
			exit(1);
		}	
		else
			echo "verify success!<br/>";
        }
        exit();
?>
