MD5 Algorithm of Cryptography in VB.NET

In this article you will learn that how you can implement MD5 Algorithm for Encryption.
  • 4817


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.

  • 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" "">
    <html xmlns="">
    <head runat="server">
        <form id="form1" runat="server">
    <table border="1"style="width: 323px; height: 76px;">
    <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>
    <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>
    <td colspan="2" style="height: 26px">
    <asp:Button ID="bntDisp" runat="server" OnClick="bntDisp_Click" Text="Add secret" /></td>
  • 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)
                Me.TxtResult.Text = Me.Md5AddSecret(Me.txtNeed.Text)
            Catch ex As Exception
            End Try
        End Sub

  • Now run your application.






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


More Articles

© 2020 DotNetHeaven. All rights reserved.