DotNet Tutorials

V4 Dot Net Tutorials

Server Intellect Cloud Hosting

 Secret by MD5 using ASP.NET 2.0 and VB.NET

This example demonstrates how to use MD5 add secret using Asp.Net2.0 and VB.Net This example demonstrates how to use MD5 add secret.

First, you will need to import the System.Collections.Cryptography and System.Collections.Text namespace.

Server Intellect offers Windows Hosting Dedicated Servers at affordable prices. I'm very pleased!


Imports System.Security.Cryptography;
Imports System.Text;

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.

Need help with Windows Dedicated Hosting? Try Server Intellect. I'm a happy customer!

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

The front end Md5AddSecretVB2005.aspx page looks something like this:

<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>

The flow for the code behind page is as follows.

If you're ever in the market for some great Windows web hosting, try Server Intellect. We have been very pleased with their services and most importantly, technical support.

Imports System Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports System.Security.Cryptography
Imports System.Text

Partial Public Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

End Sub

Public Function Md5AddSecret(ByVal strChange As String) As String
'Change the syllable into UTF8 code
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
End Class



Looking for the C#.NET 2005 Version? Click Here!

Looking for more ASP.NET Tutorials? Click Here!
Download Project Source - Enter your Email to be emailed a link to download the Full Source Project used in this Tutorial!



100% SPAM FREE! We will never sell or rent your email address!