This openssl_spki_* funcs are very usefull to use with <keygen/> tag in html5.
Example:
<?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">
Encryption: <keygen name="security" keytype="rsa" challenge="<?php echo $_SESSION['lastForm']; ?>"/>
<input type="submit">
</form>
</body>
</html>