MD5 Algorithm of Cryptography in VB.NET

In this article you will learn that how you can implement MD5 Algorithm for Encryption.
  • 1491
Download Files:
 

Introduction

Here in this article I am Discussing about MD5 Add Secret algorithm. MD5 stands for Message Digest. The implementation of example needs to import the System.Collections.Cryptography, System.Collections.Text and System.Security.Cryptography namespace. The System.Security.Cryptography namespace provides Cryptographic services including secure encoding and decoding of data, as well as many other operations, such as hashing, random number generation and message authentication.The System.Text namespace contains classes representing ASCII, Unicode, UTF-7 and UTF-8 character encodings; abstract base classes for converting blocks of characters to and from blocks of Bytes; and a helper class that manipulates and formats string objects without creating intermediate instances of string. We use the MD5AddSecret function to do the work.
 
Getting Started

  • Simply create a new ASP.NET web application. 
  • Drag a Table, TextBox and a Button control on form. Your page will look like below.

    MD5.gif
     
     
  • Now 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>
    <table border="1"style="width: 323px; height: 76px;">
    <tr>
    <td style="width: 190px; height: 28px;">&nbsp;Need To Add Secret :</td>
    <td style="width: 91px; height: 28px;">
    <asp:TextBox ID="txtNeed" runat="server" Width="128px"></asp:TextBox></td>
    </tr>
    <
    tr>
    <td style="width: 190px">
    &nbsp;Encrypt &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Result :</td>
    <td style="width: 91px">
    <asp:TextBox ID="TxtResult" runat="server" Height="17px" Width="130px" ReadOnly="True"></asp:TextBox></td>
    </tr>
    <
    tr>
    <td colspan="2" style="height: 26px">
    <asp:Button ID="bntDisp" runat="server" OnClick="bntDisp_Click" Text="Add secret" /></td>
    </tr></table>    
    </div>
        </form>
    </body>
    </
    html>
     
  • Then add the code in the code behind file of the web page.

       
    Public Function Md5AddSecret(ByVal strChange As String) As String
            Dim pass() As Byte = Encoding.UTF8.GetBytes(strChange)
            Dim md5 As MD5 = New MD5CryptoServiceProvider()
            Dim strPassword As String = Encoding.UTF8.GetString(md5.ComputeHash(pass))
            Return strPassword
        End Function
        Protected Sub bntDisp_Click(ByVal sender As Object, ByVal e As EventArgs)
            Try
                Me.TxtResult.Text = Me.Md5AddSecret(Me.txtNeed.Text)
            Catch ex As Exception
                Response.Write(ex.ToString())
            End Try
        End Sub

     
  • Now run your application.

Output

MD5-1.gif

MD5-2.gif

MD5-3.gif

Summary


In this article you learned that how to implement MD5 Add Secret Algorithm.

Categories

More Articles

© 2013 dotNetheaven. All rights reserved.