MD5 Hash

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andy Phillips

    #1

    MD5 Hash

    I'm looking for an example that given any filename as input an MD5-Hash hex
    output would be achieved.

    Anyone have this?


  • Cantelmo Software

    #2
    Re: MD5 Hash

    look at:


    Marcello





    "Andy Phillips" <andy.phillips@ callatg.com> ha scritto nel messaggio
    news:O9reW1mWFH A.2472@TK2MSFTN GP10.phx.gbl...[color=blue]
    > I'm looking for an example that given any filename as input an MD5-Hash
    > hex
    > output would be achieved.
    >
    > Anyone have this?
    >
    >[/color]


    Comment

    • Tibby

      #3
      Re: MD5 Hash

      On Mon, 16 May 2005 16:16:46 -0700, "Andy Phillips"
      <andy.phillips@ callatg.com> wrote:
      [color=blue]
      >I'm looking for an example that given any filename as input an MD5-Hash hex
      >output would be achieved.
      >
      >Anyone have this?
      >[/color]

      Try this:

      Public Function MD5_Hash(ByVal FileName As String) As String
      Dim MD5Hasher As MD5
      Dim fs As FileStream
      Dim hash() As Byte

      fs = File.Open(FileN ame, FileMode.Open)
      hash = MD5Hasher.Compu teHash(fs)
      fs.Close()
      Return BitConverter.To String(hash)
      End Function

      I haven't tested it yet, so post back and let me know who it works.

      Tibby

      Comment

      • stand__sure

        #4
        Re: MD5 Hash


        "Tibby" <tierscheiss197 7@hotmail.com> wrote in message
        news:336k81hbit 1tqb7tdvltqjc4s f0oacq1p2@4ax.c om...

        same idea, but working code from a thing that i use to check that I have
        really downloaded the same file as the author meant...

        Imports System.Security .Cryptography

        Imports System.IO

        Public Class frmMain

        Private Sub btnBrowse_Click (ByVal sender As System.Object, ByVal e As
        System.EventArg s) Handles btnBrowse.Click

        If (ofd.ShowDialog () = Windows.Forms.D ialogResult.OK) Then

        txtFileName.Tex t = ofd.FileName

        End If

        End Sub

        Private Sub btnGenerateHash _Click(ByVal sender As System.Object, ByVal e As
        System.EventArg s) Handles btnGenerateHash .Click

        Dim fs As FileStream

        Dim byt() As Byte

        If (New FileInfo(txtFil eName.Text).Exi sts) Then

        Try

        fs = File.Open(txtFi leName.Text, FileMode.Open, FileAccess.Read )

        Dim md5 As New MD5CryptoServic eProvider()

        byt = md5.ComputeHash (fs)

        txtMD5.Text = BitConverter.To String(byt)

        Dim sha1 As New SHA1CryptoServi ceProvider()

        fs.Position = 0

        byt = sha1.ComputeHas h(fs)

        txtSHA1.Text = BitConverter.To String(byt)

        Catch ex As Exception

        MessageBox.Show (ex.Message)

        Finally

        If (Not IsNothing(fs)) Then fs.Close()

        End Try

        End If

        End Sub

        End Class


        Comment

        • Andy Phillips

          #5
          Re: MD5 Hash

          I've tried using the code but I get too many build errors. I'm a VB6 native
          and hurting badly trying to move to DOTNET. I cant figure out where to place
          the code in a project with out errors. If you could please throw me a bone.
          Maybe insert the code into ??? and place this in a form?? or module or
          whatever I'd greatly appreciate it.

          Thanks
          "stand__sur e" <stand__sure@ho tmail.com> wrote in message
          news:d6eit3$o1e $1@domitilla.ai oe.org...[color=blue]
          >
          > "Tibby" <tierscheiss197 7@hotmail.com> wrote in message
          > news:336k81hbit 1tqb7tdvltqjc4s f0oacq1p2@4ax.c om...
          >
          > same idea, but working code from a thing that i use to check that I have
          > really downloaded the same file as the author meant...
          >
          > Imports System.Security .Cryptography
          >
          > Imports System.IO
          >
          > Public Class frmMain
          >
          > Private Sub btnBrowse_Click (ByVal sender As System.Object, ByVal e As
          > System.EventArg s) Handles btnBrowse.Click
          >
          > If (ofd.ShowDialog () = Windows.Forms.D ialogResult.OK) Then
          >
          > txtFileName.Tex t = ofd.FileName
          >
          > End If
          >
          > End Sub
          >
          > Private Sub btnGenerateHash _Click(ByVal sender As System.Object, ByVal e[/color]
          As[color=blue]
          > System.EventArg s) Handles btnGenerateHash .Click
          >
          > Dim fs As FileStream
          >
          > Dim byt() As Byte
          >
          > If (New FileInfo(txtFil eName.Text).Exi sts) Then
          >
          > Try
          >
          > fs = File.Open(txtFi leName.Text, FileMode.Open, FileAccess.Read )
          >
          > Dim md5 As New MD5CryptoServic eProvider()
          >
          > byt = md5.ComputeHash (fs)
          >
          > txtMD5.Text = BitConverter.To String(byt)
          >
          > Dim sha1 As New SHA1CryptoServi ceProvider()
          >
          > fs.Position = 0
          >
          > byt = sha1.ComputeHas h(fs)
          >
          > txtSHA1.Text = BitConverter.To String(byt)
          >
          > Catch ex As Exception
          >
          > MessageBox.Show (ex.Message)
          >
          > Finally
          >
          > If (Not IsNothing(fs)) Then fs.Close()
          >
          > End Try
          >
          > End If
          >
          > End Sub
          >
          > End Class
          >
          >[/color]


          Comment

          • Andy Phillips

            #6
            Re: MD5 Hash

            It works. Thanks tibby. Just had to cut out your diaglogs and textboxs and
            get the code in a module correctly. Thanks Agin



            "Andy Phillips" <andy.phillips@ callatg.com> wrote in message
            news:%23QEu2XEX FHA.2256@TK2MSF TNGP14.phx.gbl. ..[color=blue]
            > I've tried using the code but I get too many build errors. I'm a VB6[/color]
            native[color=blue]
            > and hurting badly trying to move to DOTNET. I cant figure out where to[/color]
            place[color=blue]
            > the code in a project with out errors. If you could please throw me a[/color]
            bone.[color=blue]
            > Maybe insert the code into ??? and place this in a form?? or module or
            > whatever I'd greatly appreciate it.
            >
            > Thanks
            > "stand__sur e" <stand__sure@ho tmail.com> wrote in message
            > news:d6eit3$o1e $1@domitilla.ai oe.org...[color=green]
            > >
            > > "Tibby" <tierscheiss197 7@hotmail.com> wrote in message
            > > news:336k81hbit 1tqb7tdvltqjc4s f0oacq1p2@4ax.c om...
            > >
            > > same idea, but working code from a thing that i use to check that I have
            > > really downloaded the same file as the author meant...
            > >
            > > Imports System.Security .Cryptography
            > >
            > > Imports System.IO
            > >
            > > Public Class frmMain
            > >
            > > Private Sub btnBrowse_Click (ByVal sender As System.Object, ByVal e As
            > > System.EventArg s) Handles btnBrowse.Click
            > >
            > > If (ofd.ShowDialog () = Windows.Forms.D ialogResult.OK) Then
            > >
            > > txtFileName.Tex t = ofd.FileName
            > >
            > > End If
            > >
            > > End Sub
            > >
            > > Private Sub btnGenerateHash _Click(ByVal sender As System.Object, ByVal e[/color]
            > As[color=green]
            > > System.EventArg s) Handles btnGenerateHash .Click
            > >
            > > Dim fs As FileStream
            > >
            > > Dim byt() As Byte
            > >
            > > If (New FileInfo(txtFil eName.Text).Exi sts) Then
            > >
            > > Try
            > >
            > > fs = File.Open(txtFi leName.Text, FileMode.Open, FileAccess.Read )
            > >
            > > Dim md5 As New MD5CryptoServic eProvider()
            > >
            > > byt = md5.ComputeHash (fs)
            > >
            > > txtMD5.Text = BitConverter.To String(byt)
            > >
            > > Dim sha1 As New SHA1CryptoServi ceProvider()
            > >
            > > fs.Position = 0
            > >
            > > byt = sha1.ComputeHas h(fs)
            > >
            > > txtSHA1.Text = BitConverter.To String(byt)
            > >
            > > Catch ex As Exception
            > >
            > > MessageBox.Show (ex.Message)
            > >
            > > Finally
            > >
            > > If (Not IsNothing(fs)) Then fs.Close()
            > >
            > > End Try
            > >
            > > End If
            > >
            > > End Sub
            > >
            > > End Class
            > >
            > >[/color]
            >
            >[/color]


            Comment

            Working...