當用戶點擊按鈕時,它會要求他選擇一個特定的文件。它檢查MD5哈希以確定這是否是正確的文件。在VB.NET中檢查文件的MD5
與代碼的問題是,它給了我「錯誤的文件」的消息,我完全肯定的MD5哈希的文件是「3982908442F37245B305EDCF4D834494」
Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
dim md5code as string
OpenFileDialog1.ShowDialog()
Dim md5 As MD5CryptoServiceProvider = New MD5CryptoServiceProvider
Dim f As FileStream = New FileStream(OpenFileDialog1.FileName, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
f = New FileStream(OpenFileDialog1.FileName, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
md5.ComputeHash(f)
Dim ObjFSO As Object = CreateObject("Scripting.FileSystemObject")
Dim objFile = ObjFSO.GetFile(OpenFileDialog1.FileName)
Dim hash As Byte() = md5.Hash
Dim buff As StringBuilder = New StringBuilder
Dim hashByte As Byte
For Each hashByte In hash
buff.Append(String.Format("{0:X1}", hashByte))
Next
md5code = buff.ToString()
If md5code = "3982908442F37245B305EDCF4D834494" Then
TextBox2.Text = OpenFileDialog1.FileName
Else
MessageBox.Show("Wrong File")
End If
End Sub
除了 「{0:X2}」'? – samjudson
恩....爲什麼你在混合VBS和VB.NET?這自然會導致問題......一次又一次。 – specializt