Title
Fetch HTML 5 Keygen Tag Value – ASP.Net
Introduction
The <keygen> tag specifies a key- pair generator field user for forms. When the form is submitted, the private key is stored locally and the public key is sent to the server.
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> </head> <body> <form action="Default.aspx" method="post"> <table> <tr> <th> User Name: </th> <td> <input type="text" name="username" /> </td> </tr> <tr> <th> Encryption: </th> <td> <keygen keytype="rsa" name="security" /> </td> </tr> </table> <input type="submit" value="Submit" /> </form> </body> </html>
We can either use ASP.Net or PHP to capture the encryption key.
Below code will capture the key value and display on the web page.
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string userName = Request["username"].ToString(); string key = Request["security"].ToString(); lblKey.Text = "Username = " + userName + " and Key = " + key; } }
Note:
Keytype specifies the encryption algorithm, in this case keytype=”rsa”, i.e. RSA encryption algorithm will be used to encrypt the data.
OUTPUT