Hash a string using MD5 hash algorithm

/ Published in: VB.NET
Save to your folder(s)

This function accepts a string and converts it to its corresponding 32 bit hexadecimal MD5 hash. It comes in handy for encrypting passwords and keys.

Copy this code and paste it in your HTML
  1. Public Shared Function getMD5Hash(ByVal strToHash As String) As String
  2. Dim md5Obj As New System.Security.Cryptography.MD5CryptoServiceProvider()
  3. Dim bytesToHash() As Byte = System.Text.Encoding.ASCII.GetBytes(strToHash)
  5. bytesToHash = md5Obj.ComputeHash(bytesToHash)
  7. Dim strResult As String = ""
  8. Dim b As Byte
  10. For Each b In bytesToHash
  11. strResult += b.ToString("x2")
  12. Next
  14. Return strResult
  15. End Function

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.