这些 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 'Ok, this one is valid.', '<br><br>';
}
else
{
echo 'Nice try... nice try...', '<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>