Skip to content
Related Articles

Related Articles

Improve Article

How to generate public key in HTML ?

  • Last Updated : 25 Jul, 2021

You can easily generate a public key using the <keygen> tag in HTML. The <keygen> element generates an encryption key for passing encrypted data to a server. The purpose of the <keygen> element is to provide a secure way to authenticate users.

Actually, when a form is submitted then two keys are generated, private key and public key. The private key is stored locally, and the public key is sent to the server. The public key is used to generate a client certificate to authenticate the user for the future.

Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.

Syntax:

<keygen name="name" challenge="challenge" 
    keytype="type" keyparams="pqg-params">

Attributes Value:



  • name: Specify a name for the keygen element, which is submitted with the form data.
  • keytype:   Specify what type of key is to be generated. Values are “RSA”, “DSA” and “EC” and “RSA” is by default.
  • challenge:  A challenge string that is submitted along with the public key. Defaults to an empty string if not specified.
  • form: Specifies the <form> element that the <keygen> element is associated with.

Note: The keyparams attribute is required for DSA and EC key generation.

Example: 

HTML




<!DOCTYPE html>
<html>
  
<body>
    <center>
        <h1 style="color:green;">
            GeeksforGeeks
        </h1>
  
        <h2>Keygen Tag</h2>
  
        <form>
            <label>Username:
                <input type="text" name="username"></label>
            </br>
            <label>Password:
                <input type="password" name="password"></label>
            </br>
            <label>Encryption: <keygen name="key"></label>
            <input type="submit" value="Submit">
        </form>
    </center>
</body>
  
</html>     

Output:

keygen tag




My Personal Notes arrow_drop_up
Recommended Articles
Page :