Posted By

psybuck2002us on 08/05/10


Tagged

hashalgorithmmd5encryptencryption


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

startupbrite
D4RKCODE


Hash a string using MD5 hash algorithm


 / Published in: VB.NET
 

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.

  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)
  4.  
  5. bytesToHash = md5Obj.ComputeHash(bytesToHash)
  6.  
  7. Dim strResult As String = ""
  8. Dim b As Byte
  9.  
  10. For Each b In bytesToHash
  11. strResult += b.ToString("x2")
  12. Next
  13.  
  14. Return strResult
  15. End Function

Report this snippet  

You need to login to post a comment.