ARTICLE

How to perform Encryption with SHA1 and MD5 in VB.NET

Posted by Shalini Juneja Articles | Cryptography in VB.NET May 13, 2011
In this article you will learn that how you can perform Encryption with SHA1 and MD5
Download Files:
 
Reader Level:

Introduction

Here in this article we are discussing that how can you Encrypt your password or any string by selecting any of the cryptography Algorithm Either by SHA1 or MD5. The implementing of this example needs to import System.web.Security namespace and you will also add four controls as two TextBox, Button, DropDownList and a Label control. You will select Algorithm for Encryption from DropDownList. The namespace will be inherited by Forms Authentication class in which you will get the HashPasswordForStoringInConfigFile method. This method is used for the conversion of password or any string into Encrypted format.


Getting Started

  • Simply Create a new ASP.NET web application.
  • Drag two TextBox, Button, DropDownList and a Label control on your page. The page will look like below.

    pass2.gif

  • Your Default.aspx page will look like below.

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <title></title
    >
    </head>
    <
    body>
    <form id="form1" runat="server">
    <div>
    </div>
    <asp:TextBox ID="txtResult" runat="server"></asp:TextBox
    >
    &nbsp;&nbsp;&nbsp;
    <asp:Button ID="btnEncrypt" runat="server" Text="PerformEncryption" />
    &nbsp;&nbsp;
    <br />
    <br />
    <asp:DropDownList ID="Selectalgo" runat="server" Height="16px">
    <asp:ListItem>SHA1</asp:ListItem>
    <asp:ListItem>MD5</asp:ListItem>
    </asp:DropDownList>
    <br />
    <br />
    <br />
    <br />
    <asp:Label ID="DisplayResult" runat="server" Text="EncryptedResult"></asp:Label
    >
    &nbsp;&nbsp;
    <asp:TextBox ID="txtDisplayValue" runat="server"></asp:TextBox>
    </form
    >
    </body>
    </
    html>

  • Then add the below code in code behind file of the web page.

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
    If Me.IsPostBack = False Then
    Selectalgo.Items.Add("")
    Selectalgo.SelectedValue = ""
    End If
    End Sub
    Protected Sub btnEncrypt_Click(sender As Object, e As System.EventArgs) Handles btnEncrypt.Click
    txtDisplayValue.Text = FormsAuthentication.HashPasswordForStoringInConfigFile(txtResult.Text, Selectalgo.SelectedValue)
    End
    Sub


  • Now run your application.


Output:-

pass3.gif


pass4.gif


pass5.gif


pass6.gif

pass8.gif

Summary
 
In this article you learned that how to perform Encryption

Login to add your contents and source code to this article
share this article :
post comment
 
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Nevron Diagram
Become a Sponsor