Open In App

How to define a key-pair generator field in HTML5 ?

Last Updated : 16 Jun, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The HTML <keygen> element can help generate a key material as part of an HTML form and submit the public key. This mechanism is intended for use with certificate systems based on the web. The <keygen> element is expected to be used in an HTML form along with additional information necessary to build a certificate request, and a signed certificate will be the result of the process.

Syntax: The syntax of <keygen> tag is

<keygen name="name">

Example 1: In this example, we will use <keygen> tag

HTML




<!DOCTYPE html>
<html>
<head>
    <title>GFG</title>
</head>
<body>
    <form action="/gfg" method="post">
        <label>Username: <input type="text" name="uname"></label>
        <label>Encryption: <keygen name="lock"></label>
        <input type="submit" value="Submit">
    </form>
</body>
 
</html>


Output:

keygen

Example 2: In this example, we will generate a key from <keygen> tag

HTML




<!DOCTYPE html>
<html>
<head>
    <title>GFG</title>
</head>
<body>
    <form>
        <keygen name="key" challenge="000">
        <input name="name" value="Name">
    </form>
</body>
</html>


Output:

keygen challenge



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

Similar Reads