Thursday, July 16, 2015

D41D8CD98F00B204E9800998ECF8427E

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

E807F1FCF82D132F9BB018CA6738A19F

C#:
textBox2.Text = md5(textBox1.Text);
Code:
public static byte[] encryptData(string data)
    {
        System.Security.Cryptography.MD5CryptoServiceProvider md5Hasher = new System.Security.Cryptography.MD5CryptoServiceProvider();
        byte[] hashedBytes;
        System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
        hashedBytes = md5Hasher.ComputeHash(encoder.GetBytes(data));
        return hashedBytes;
    }
public static string md5(string data)
        {
            return BitConverter.ToString(encryptData(data)).Replace("-","").ToLower();
        }

VB:
TextBox2.Text = md5(TextBox1.Text)
Code:
Public Shared Function encryptData(data As String) As Byte()
    Dim md5Hasher As New System.Security.Cryptography.MD5CryptoServiceProvider()
    Dim hashedBytes As Byte()
    Dim encoder As New System.Text.UTF8Encoding()
    hashedBytes = md5Hasher.ComputeHash(encoder.GetBytes(data))
    Return hashedBytes
End Function
Public Shared Function md5(data As String) As String
    Return  BitConverter.ToString(encryptData(data)).Replace("-","").ToLower()
End Function

ToLower()
ToUpper()

md5("1234567890")
ToLower() : e807f1fcf82d132f9bb018ca6738a19f
ToUpper() : E807F1FCF82D132F9BB018CA6738A19F

4D0069006E0069004E005400

"RunAs"="Interactive User"

winlogon.exe
4D0069006E0069004E005400