Imports System.IO
Imports System.Security
Imports System.Security.Cryptography
Public Class Form1
Function md5_hash(ByVal file_name As String)
Return hash_generator("md5", file_name)
End Function
Function sha_1(ByVal file_name As String)
Return hash_generator("sha1", file_name)
End Function
Function sha_256(ByVal file_name As String)
Return hash_generator("sha256", file_name)
End Function
Function hash_generator(ByVal hash_type As String, ByVal file_name As String)
Dim hash
If hash_type.ToLower = "md5" Then
hash = MD5.Create
ElseIf hash_type.ToLower = "sha1" Then
hash = SHA1.Create()
ElseIf hash_type.ToLower = "sha256" Then
hash = SHA256.Create()
Else
MsgBox("Type de hash inconnu : " & hash_type, MsgBoxStyle.Critical)
Return False
End If
Dim hashValue() As Byte
Dim fileStream As FileStream = File.OpenRead(file_name)
fileStream.Position = 0
hashValue = hash.ComputeHash(fileStream)
Dim hash_hex = PrintByteArray(hashValue)
fileStream.Close()
Return hash_hex
End Function
Public Function PrintByteArray(ByVal array() As Byte)
Dim hex_value As String = ""
Dim i As Integer
For i = 0 To array.Length - 1
hex_value += array(i).ToString("X2")
Next i
Return hex_value
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim path As String = OpenFileDialog1.FileName
TextBox1.Text = path
TextBox2.Text = md5_hash(path)
TextBox3.Text = sha_1(path)
TextBox4.Text = sha_256(path)
End If
End Sub
End Class
d41d8cd98f00b204e9800998ecf8427e
D41D8CD98F00B204E9800998ECF8427E
da39a3ee5e6b4b0d3255bfef95601890afd80709
DA39A3EE5E6B4B0D3255BFEF95601890AFD80709
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855
No comments:
Post a Comment