Open In App

How to generate public key in HTML ?

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:



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

Example: In this example, we will see the use of <keygen> tag




<!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


Article Tags :