Open In App

How to generate public key in HTML ?

Last Updated : 29 May, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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.

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: In this example, we will see the use of <keygen> tag

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



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads