Implement One Way Encryption in ASP.NET using VB.NET

In this article you will learn that how can you encrypt your password before storing it by one way encryption technique.
  • 3708


Here in this article I am describing that how you can encrypt your password in ASP.NET using One Way Encryption and how to secure your password before saving in the database or XML file etc. Attackers and Hackers are always try to attack the database and stole password stored in database. It is the responsibility of the developer to encrypt the password before storing the database. One Way Encryption is secure to protect the password. One Way Encryption is Encrypt the password but not Decrypt. In this example I have used SHA512Managed Class. The size of SHA512Managed algorithm is 512 bits.

Getting Started with One Way Encryption

  • Simply create a new ASP.NET web application. 
  • Drag one Textbox, RequiredFieldValidator, Button and two Label control on your web page. 
  • The design mode of your web page will look like below page.

  • The Source mode of the web page will look like below.

    <%@ Page Title="Home Page" Language="vb" MasterPageFile="~/Site.Master" AutoEventWireup="false"
        CodeBehind="Default.aspx.vb" Inherits="One_way_Encrytion._Default" %>
    <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
    asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
                background: #fefefe;
                font-size: .80em;
                font-family: "Helvetica Neue" , "Lucida Grande";
                margin: 0px;
                 padding: 0px;
                color: #222;
            Implementing One-way Encryption in using VB.NET </h2>
                <asp:TextBox ID="TextBox1" runat="server" />
                <asp:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click" />
                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Enter the Password."
                    ControlToValidate="TextBox1" ForeColor="Red"></asp:RequiredFieldValidator></br>
                <br />
                <asp:Label ID="Label1" runat="server" />
  • Then add the below code on the code behind file of the web page.

    Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
            Label1.Text = "Encrypted password:  " +
        End Sub
        Public Shared Function getEncryptedCode(ByVal inputString As String) As String
            Dim Hash As Byte() = New System.Security.Cryptography.SHA512Managed().ComputeHash(System.Text.ASCIIEncoding.ASCII.GetByt
            Dim outputString As New System.Text.StringBuilder()
            For i As Integer = 0 To Hash.Length - 1
            Return outputString.ToString()
        End Function

  • Now run your application.






In this article you learned that how you can encrypt your password by One Way Encryption and save it from attackers.


More Articles

© 2020 DotNetHeaven. All rights reserved.