<?php
require "webprotect.php";

// 出力バッファリング
ob_start();

session_start();

	$wp = new WebProtect();


	if( !isset( $_REQUEST["submit"] ) )
	{
		header("Content-Type: text/html");
		$wp->setHeaders();

		// USBキー認証に必要なデータを保存
		$_SESSION['challenge0_key'] = $wp->challenge[0];
		$_SESSION['challenge1_key'] = $wp->challenge[1];

		printLoginPage();
	}
	else
	{
		// 保存データ読み込み
		$challenge_key[0] = $_SESSION['challenge0_key'];
		$challenge_key[1] = $_SESSION['challenge1_key'];

		session_destroy();

		header("Content-Type: text/html");
		$wp->setHeaders();

		authenticateKey($challenge_key);

	}

// 出力取得
$output = ob_get_contents();
ob_end_clean();

// 出力の暗号化と送出
echo $wp->encBuffer($output);

exit;

//認証処理
function authenticateKey($challenge)
{

print <<<EOT
<html>
<head>
<title>Result</title>
<body>
EOT;

	$hashReturned="";

	// retrieve "mxkey-id" header value
	foreach (getallheaders() as $name => $value) 
	{
		if( $name === "mxkey-id" )
			$hashReturned = $value;
	}

	// 初期シリアル番号
	$serNr = 1000000000;

	// 保有USBキーのシリアル番号からハッシュ算出
	for( $i=0 ; $i < 1500 ; $i++ )
	{
		$rawString = $challenge[0] . "-" . $serNr . "-" . "1234-" . $challenge[1];

		$hash = hash("sha256", $rawString, true);
		$hashBase64 = base64_encode($hash);

		// 同一ハッシュ!
	       if( $hashBase64 === $hashReturned )
			break;

		$serNr++;
	}

	if( $i == 1500 )
		echo "見つかりませんでした";
	else
	{
		echo "SerNr == " . $serNr . "<br>";
		echo "PIN=" . $_REQUEST["pin"] . "<br>";
	}

print <<<EOT
</body>
</html>
EOT;

}

//ログインページ
function printLoginPage()
{
?>

<html>
<head>
<title>test</title>
<body>
<form method="post" >
	<input type="password" name="pin" size="8" maxlength="6" />
	<input type="submit" value="Ok" name="submit" />
</form>

</body>
</html>

<?php
}

?>

Java では暗号フォルダ内 servlet/jsp ファイルを暗号化フィルタにマップすることで PHP コードと 同等の処理が可能です( サンプル提供可能 )