zbeng Posted December 9, 2006 Report Share Posted December 9, 2006 This will be the first of the few Tutorials of how to create fun applications using VisualBasic2005 Express Edition. A Basic experience of using VisualBasic2005 is expected.I will not be going into how the MD5 algorithm works. For that you can look at the following URLhttp://www.ietf.org/rfc/rfc1321.txtNow, create a new project after you launch VisualBasic2005.1-> Rename "Form1.vb" as "HashCalc_MainFrm"2-> Create a label on the form and name it "InputFileName"(this will hold the name of the file you are using)3-> Create a textbox on the form and name it "CalcMD5Hash"(this will hold the calculated MD5 Hash)4-> Create a button on the form and name it "SelectInputFile" and put "...." in the text for the button.5-> Now in the toolbox browse to dialogs, select the openfiledialog(toolbox->dialogs->OpenFileDialog) and drag-drop onto the form. Rename this dialog as "OpenFileForHashing"Now you are all set to go Very Happy.Look at the image below to get an idea of what i am talking about. Now click on the "view code" button to goto the code view of the form and paste the following code. Imports System.IOImports SystemImports System.Security.CryptographyImports System.TextPublic Class HashCalc_MainFrm Private Sub SelectInputFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SelectInputFile.Click 'Set some options for the FileOpenDialog OpenFileForHashing.CheckFileExists = True OpenFileForHashing.CheckPathExists = True 'Show the FileOpenDialog OpenFileForHashing.ShowDialog() 'Show the name of the file selected in the label on the form InputFileName.Text = OpenFileForHashing.FileName Dim fileOpen As FileStream = New FileStream(OpenFileForHashing.FileName, FileMode.Open) ' Create a new instance of the MD5 object. Dim md5Hasher As MD5 = MD5.Create() ' Convert the input file to a byte array and compute the hash. Dim data As Byte() = md5Hasher.ComputeHash(fileOpen) ' Create a new Stringbuilder to collect the bytes ' and create a string. Dim sBuilder As New StringBuilder() ' Loop through each byte of the hashed data ' and format each one as a hexadecimal string. Dim i As Integer For i = 0 To data.Length - 1 sBuilder.Append(data(i).ToString("x2")) Next i fileOpen.Dispose() CalcMD5Hash.Text = sBuilder.ToString().ToUpper End Sub Private Sub HashCalc_MainFrm_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing 'Clean up InputFileName.Text = Nothing CalcMD5Hash.Text = Nothing End SubEnd ClassHere is how your application looks like when you run it. You can calculate the hash for any kind of file.Happy Coding Very Happy Quote Link to comment Share on other sites More sharing options...