What is <keygen> tag in HTML?


In HTML <keygen> tag is one of the element which is responsible for generating a pair of public and private keys.

  • Public and private keys are used to encrypt and decrypt the data, that is sent to server, whenever an HTML form is submitted.

  • Private key is stored on User’s local device, whereas public key is sent to server along with submitted dorm data.

  • The <keygen> tag is used to create and verify the digital signature also.

  • <keygen> tag is used to generate key and it also allows the user to choose from a range of key size options.

Syntax

Following is the usage of <keygen> tag in HTML -

<keygen name = "name">

Example

Following example of the <keygen> tag in HTML.

<!DOCTYPE html>
<html>
<head>
   <title>Keygen tag</title>
</head>
<body>
   <h1 style="color:blue;"> TutorialsPoint </h1>
   <form action="/form/submit" method="get">
      <keygen name="rsaPublicKey" keytype="RSA"> User’s name: <input type="text" name="usr_name">
      <br>
      <br> E-mail <input type="text" name="email">
      <br>
      <br>
      <input type="submit">
   </form>
</body>
</html>

Now, let us see the attributes used for <keygen> tag in HTML. The <keygen> tag supports the following additional attributes −

S.No.

Attribute & Description

autofocus

Autofocus

Autofocus Specifies that when the page loads the <keygen> element automatically gets focus.

challenge

Challenge

Specifies the challenge string to be packaged with the public key in the PublicKeyAndChallenge for use in verification of the form submission. If no challenge string is provided, then it is encoded as an IA5STRING of length zero.

disabled

disabled

disabled Specifies that <keygen> element should be disabled

form

form_id

Specifies one or more forms

keytype

Rsadsaec

Specifies the secret algorithm which is for the key.

Example

Following is another example of the <keygenl> tag in HTML.

<!DOCTYPE html>
<html>
<head>
   <title>Keygen tag</title>
</head>
<body>
   <h1 style="color:blue;"> TutorialsPoint </h1>
   <form action="/form/submit" method="get">
      <keygen name="rsaPublicKey" key <!DOCTYPE html>
      <style>
         body {
            text-align: center;
            background-color: gray;
            font-size: 25px;
         }
         button {
            background-color: yellow;
            border: none;
            color: black;
            padding: 5px 32px;
            text-align: center;
            text-decoration: none;
            display: inline-block;
            font-size: 16px;
         }
      </style>
      <h1 style="color:blue">TutorialsPoint</h1>
      <form id="form1"> Name: <input type="text" name="user_name">
         <button>Submit</button>
      </form>
      <p> The keygen tag is a part of the form, but it was created outside the form element. </p> Encrypted: <keygen name="security" form="form1">
      <br>
      <br> E-mail <input type="text" name="email">
      <br>
      <br>
      <input type="submit">
   </form>
</body>
</html>

Updated on: 10-Oct-2023

156 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements