這些 openssl_spki_* 函式對於 HTML5 中的 <keygen/> 標籤非常有用。
範例
<?php
session_start();
if(isset($_POST['security']))
{
if(openssl_spki_verify($_POST['security']))
{
$challenge = openssl_spki_export_challenge($_POST['security']);
if($challenge == $_SESSION['lastForm'])
{
echo '好的,這個有效。', '<br><br>';
}
else
{
echo '想得美... 想得美...', '<br><br>';
}
}
}
$_SESSION['lastForm'] = hash('md5', microtime(true));
?>
<!DOCTYPE html>
<html>
<body>
<form action="/index.php" method="post">
加密: <keygen name="security" keytype="rsa" challenge="<?php echo $_SESSION['lastForm']; ?>"/>
<input type="submit">
</form>
</body>
</html>