MD5 Hash by String





8
Date Submitted Sat. Sep. 23rd, 2006 5:06 AM
Revision 1 of 1
Scripter Pio
Tags MD5 | Security | VB.NET
Comments 1 comments
This could be used for any type of simple hash checking. It could also be used to store a "password" that had to be verified. This code is completely managed.

  Public Shared Function GetMD5Hash(ByVal str As String) As String
    Try
      Dim MD5Hasher As New MD5CryptoServiceProvider
      Dim rawBytes As Byte() = ASCIIEncoding.ASCII.GetBytes(str)
      Dim myHash As Byte() = MD5Hasher.ComputeHash(rawBytes)
      Dim myCapacity As Integer = Convert.ToInt32(((myHash.Length * 2) + (myHash.Length / 8)))
      Dim sb As System.Text.StringBuilder = New System.Text.StringBuilder(myCapacity)

      For i As Integer = 0 To myHash.Length - 1
        sb.Append(BitConverter.ToString(myHash, i, 1))
      Next

      Return sb.ToString().TrimEnd(New Char() {" "c}).ToLower
    Catch ex As Exception
      Debug.WriteLine(ex.ToString)
      Return "Error occured."
    End Try
  End Function
 

Allen Gammel

p-soft.org
Allen / Pio
email: intolerance@gmail.com

Comments

Comments Thank you
Thu. Jul. 5th, 2007 8:38 AM    Beginner babakzawari

Voting