ARTICLE

How to implement MD5 Algorithm of Cryptography in ASP.NET using VB.NET

Posted by Dea Saddler Articles | Cryptography in VB.NET May 12, 2011
In this article you will learn that how you can implement MD5 Algorithm for Encryption
Download Files:
 
Reader Level:

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.

Login to add your contents and source code to this article
share this article :
post comment
 
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor