(03-02-2013, 06:42 PM)BreShiE Wrote: Version 2 is out. This gives you more check sums and the exact file size in bytes, for a deeper look into the legitimacy of the scan.
Keep in mind filesize is essentially part of a hashing algorithm.
(03-02-2013, 02:29 AM)The Anarchist Wrote: Not sure if it's clean, but checking the MD5 hash is always a good idea when downloading stuff.
It's a
start to a good idea. MD5 collisions are more commonly matched now so it is not a guarantee that the integrity of the file is still up to par... You should be comparing with SHA1 minimum in my opinion, or something a bit more aggressive like SHA256.
Code:
Private Function GetFileSize(ByVal MyFilePath As String) As Long
Dim num As Long
Dim info As New FileInfo(MyFilePath)
Dim str As String = Conversions.ToString(info.Length)
Me.TextBox5.Text = (str & " (in bytes)")
Return num
End Function
Do you actually has a function that returns 0 all the time and acts as a Sub for the most part? You should also just call the ToString() method instead of converting to a string that way in my opinion.
Code:
Private Function ByteArrayToString(ByVal arrInput As Byte()) As String
Dim builder As New StringBuilder((arrInput.Length * 2))
Dim num2 As Integer = (arrInput.Length - 1)
Dim i As Integer = 0
Do While (i <= num2)
builder.Append(arrInput(i).ToString("X2"))
i += 1
Loop
Return builder.ToString.ToLower
End Function
No for loop here?
Code:
Private Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs)
Clipboard.Clear
Clipboard.SetText(Me.TextBox2.Text)
Interaction.MsgBox("Hash copied!", MsgBoxStyle.Information, Nothing)
End Sub
Private Sub Button3_Click(ByVal sender As Object, ByVal e As EventArgs)
Clipboard.Clear
Clipboard.SetText(Me.TextBox3.Text)
Interaction.MsgBox("Hash copied!", MsgBoxStyle.Information, Nothing)
End Sub
Private Sub Button4_Click(ByVal sender As Object, ByVal e As EventArgs)
Clipboard.Clear
Clipboard.SetText(Me.TextBox4.Text)
Interaction.MsgBox("Hash copied!", MsgBoxStyle.Information, Nothing)
End Sub
When you call SetText(), it clears out all pre-existing data anyways, so no need to call Clear() here. Why are you using MsgBox() though?
Aside from it's use, Nothing is the default argument value anwyays for the overload that you are calling here, so really you only needed this: MsgBox("Hash copied!", MsgBoxStyle.Information)
Code:
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Me.OpenFileDialog1.ShowDialog
Me.TextBox1.Text = Me.OpenFileDialog1.FileName
Me.MD5CalcFile(Me.OpenFileDialog1.FileName)
Me.GetFileSize(Me.OpenFileDialog1.FileName)
Me.Button2.Enabled = True
Me.Button3.Enabled = True
Me.Button4.Enabled = True
End Sub
What if they press cancel button. No error handling here?? Not to mention... You've got
both MD5CalcFile() and GetFileSize() declared as functions, but they aren't used like a function as you're not doing anything with the return values. What you did for the return values was completely unnecessary.
Code:
Public Function MD5CalcFile(ByVal filepath As String) As String
Using stream As FileStream = New FileStream(filepath, FileMode.Open, FileAccess.Read)
Using provider As MD5CryptoServiceProvider = New MD5CryptoServiceProvider
Using provider2 As SHA1CryptoServiceProvider = New SHA1CryptoServiceProvider
Using provider3 As SHA256CryptoServiceProvider = New SHA256CryptoServiceProvider
Dim str As String
Dim arrInput As Byte() = provider.ComputeHash(stream)
Dim buffer2 As Byte() = provider2.ComputeHash(stream)
Dim buffer3 As Byte() = provider3.ComputeHash(stream)
Me.TextBox2.Text = Me.ByteArrayToString(arrInput)
Me.TextBox3.Text = Me.ByteArrayToString(buffer2)
Me.TextBox4.Text = Me.ByteArrayToString(buffer3)
Return str
End Using
End Using
End Using
End Using
End Function
Function:
- Dim str As String
- Return String
???
This is a horrible use of the Using statement as well. They should never be intertwined like that because they are in no way related to one another. So even if you are done with one object, it's Dispose() method will never be called until everything is done with, and that is poor design.