Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged TextBox2.Text = MD5CalcFile(TextBox1.Text)
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPrivate Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged TextBox2.Text = MD5CalcFile(TextBox1.Text)
Imports System.Security.Cryptography Imports System.IO Public Class Form1 Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim dialog As New OpenFileDialog() OpenFileDialog1.Filter = "All files (*.*)|*.*" If DialogResult.OK = OpenFileDialog1.ShowDialog Then TextBox1.Text = OpenFileDialog1.FileName End If Dim path As String = TextBox1.Text TextBox2.Text = MD5CalcFile(path) End Sub Public Function MD5CalcFile(ByVal filepath As String) As String Try Using reader As New System.IO.FileStream(filepath, IO.FileMode.Open, IO.FileAccess.Read) Using md5 As New System.Security.Cryptography.MD5CryptoServiceProvider Dim hash() As Byte = md5.ComputeHash(reader) Return ByteArrayToString(hash) End Using End Using Catch ex As Exception Return "" End Try End Function Public Function ByteArrayToString(ByVal arrInput() As Byte) As String Try 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 Catch ex As Exception Return "" End Try End Function Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged TextBox2.Text = MD5CalcFile(TextBox1.Text) End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim dialog As New OpenFileDialog() OpenFileDialog1.Filter = "All files (*.*)|*.*" If DialogResult.OK = OpenFileDialog1.ShowDialog Then TextBox1.Text = OpenFileDialog1.FileName End If Dim path As String = TextBox1.Text TextBox2.Text = MD5CalcFile(path) End Sub