File MD5# and SHA# Calculator-VBForums
Results 1 to 4 of 4

Thread: File MD5# and SHA# Calculator

  1. #1

    Thread Starter
    Frenzied Member i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    1,772

    Lightbulb File MD5# and SHA# Calculator

    After seeing a long-winded version on the forums about how to generate a MD5# for a file I thought I'd post how to do this here...

    vb.net Code:
    1. Private Function CalcMD5(ByVal File As String) As String
    2.         Dim f = New IO.FileStream(File, IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.Read, 4096)
    3.         Dim md5 As New System.Security.Cryptography.MD5CryptoServiceProvider
    4.         Return Join((From xItem In md5.ComputeHash(f) Select xItem.ToString("X2")).ToArray, "")
    5.     End Function

    Also you could use the following to calculate the older (and slower) SHA#:
    vb.net Code:
    1. Private Function CalcSHA(ByVal File As String) As String
    2.         Dim f = New IO.FileStream(File, IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.Read, 4096)
    3.         Dim sha1 As New System.Security.Cryptography.SHA1CryptoServiceProvider
    4.         Return Join((From xItem In sha1.ComputeHash(f) Select xItem.ToString("X2")).ToArray, "")
    5.     End Function

    Hope this helps some people ...
    Also please provide feedback and say thanks if this helped you

    Kris

  2. #2
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: File MD5# and SHA# Calculator

    You've got your facts a bit backwards there... SHA-X is much newer than MD5 and MD5 is now deemed somewhat insecure. Several collisions have been found for MD5 but none for SHA at all (except for reduced SHA). Also, a test has shown that .NET MD5 and SHA-1 implementations are about the same speed.

  3. #3

    Thread Starter
    Frenzied Member i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    1,772

    Re: File MD5# and SHA# Calculator

    Hrm interesting ... i know that SHA is more accurate... but MD5 should be quite accurate also as the chances of duplication are 1 in 16^32 arn't they, also i remember old zip programs using sha and now they all seem to use md5?

    Kris

  4. #4
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: File MD5# and SHA# Calculator

    I've never used hashing ZIP programs so I wouldn't know. Maybe they've always supported SHA but had nothing to do so decided to add other options?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.