HTML5

HTML5 keygen tag: A new field for key generation

With HTML5 keygen tag we continue to discover the new HTML5 fields.

This tag is used to send keys in web authentication. When the form is submitted, two keys are created, one public key that is sent to the server and will later be used to continue authentication in the system, and another private key that is stored locally in the browser.

Deprecated tag

This is deprecated since 2018.

Syntax of HTML5 keygen tag

The syntax is very simple, here I put its code:

<keygen name="pass">

As you can see, it is a tag that is assigned a name.

Keygen’s important attributes

  • keytype: Type of key sent, by default is RSA. Other key types are: EC and DSA.
  • challenge: Specifies if the key changes after sending the form.
  • form: Id of the form the key belongs to.

More info about the HTML5 keygen in this link.

Example of HTML5 keygen tag

In the following example of HTML5 keygen we will see the value of the sent public key. Once you press the send button, you will see how a box calculates the key:

<form action="form.php" method="post">
    User: <input type="text" name="user">
    Pass: <keygen name="pass">
    <input type="submit" value="Send">
</form>

I put the PHP code to obtain the public key sent by POST.

<?php 
if ($_POST['pass'])
    echo "Public key: " .$_POST['pass'];
?>
Share
Published by
Aner Barrena