04-18-2011, 12:39 PM
The code:
The download link: http://7019.a.hostable.me/CheckMD5.exe
And an image:
Spoiler (Click to View)
Code:
Imports System.IO
Imports System.Security.Cryptography
Imports System.Text
Public Class Form1
Private Sub FButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FButton1.Click
If OpenFileDialog1.ShowDialog(Me) = 1 Then
txtFile1.Text = OpenFileDialog1.FileName
Label3.Text = GetFileSize(txtFile1.Text).ToString & "kb"
End If
End Sub
Private Function GetFileSize(ByVal MyFilePath As String) As Long
Dim MyFile As New FileInfo(MyFilePath)
Dim FileSize As Long = MyFile.Length
Return FileSize
End Function
Private Sub FButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FButton2.Click
If OpenFileDialog2.ShowDialog(Me) = 1 Then
txtFile2.Text = OpenFileDialog2.FileName
Label4.Text = GetFileSize(txtFile2.Text).ToString & "kb"
End If
End Sub
Private Sub FButton3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FButton3.Click
Me.Close()
End Sub
Private Sub FButton4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FButton4.Click
Dim pipi As String = CalculateMD5(txtFile1.Text)
Dim kaka As String = CalculateMD5(txtFile2.Text)
If pipi = kaka Then
MessageBox.Show("The 2 files are the same", "Yes!!")
Else
MessageBox.Show("Those are 2 different files", "Oh noes :(")
End If
End Sub
Private Function CalculateMD5(ByVal strFilepath As String) As String
Dim File() As Byte = System.IO.File.ReadAllBytes(strFilepath)
Dim Md5 As New MD5CryptoServiceProvider()
Dim byteHash() As Byte = Md5.ComputeHash(File)
Return ByteArrayToString(byteHash)
End Function
Private Function ByteArrayToString(ByVal arrInput() As Byte) As String
Dim sb As New System.Text.StringBuilder(arrInput.Length * 2)
For i As Integer = 0 To arrInput.Length - 1
sb.Append(arrInput(i).ToString("X2"))
Next
Return sb.ToString().ToLower
End Function
End Class
And an image: