Password Encryption Technique Cryptography in VB.NET

In this article you will learn that how can you encrypt your password with SHA512Managed Algorithm
  • 2867
Download Files:
 

Introduction

Here in this article we are discussing that how can you Encrypt your password with Encryption technique of cryptography. By using Encryption you can secure your password from hackers. Encryption is a secure technique to protect the password. In this example we are using SHA512Managed class. This is a cryptography algorithm for password Encryption. The size of the 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.

    encrypt1.gif
     
  • The Source mode of the web 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">
        <style>
            body
            {
               
    background: #fefefe;
               
    font-size: .80em;
               
    font-family: "Helvetica Neue" , "Lucida Grande";
               
    margin: 0px;
                
    padding: 0px;
               
    color: #222;
            }
       
    </style>
        <div>
        <h2>
             Cryptography Password Encryption technique in VB.NET </h2>
            <p>
                Password:
               
    <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" />
            </p>
        </div>
        </form>
    </
    body>
    </
    html>
     
  • Then add the below code on the code behind file of the web page.

        Protected
    Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
            Label1.Text = "Encrypted password:  " +
                          getEncryptedCode(TextBox1.Text.Trim().ToString())
        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
             (inputString))
            Dim outputString As New System.Text.StringBuilder()
            For i As Integer = 0 To Hash.Length - 1
                outputString.Append(Hash(i).ToString("x2"))
            Next
            Return outputString.ToString()
        End Function

     
  • Now run your application.
Output:

encrypt2.gif

encrypt3.gif

encrypt4.gif

Summary

In this article you learned that how you can encrypt your password by cryptography Encryption technique.

Categories

More Articles

© 2018 DotNetHeaven. All rights reserved.