Login or Sign Up to become a member!

EXPERTS, INFORMATION, IDEAS & KNOWLEDGE

Social bookmarker Add this

ASP.NET: Encrypt a string using MD5

From Wiki

Jump to: navigation, search


Summary: Encrypt a string using MD5 encryption

Pass a string to the function and look at the returned string which is MD5 encrypted.

  1. Public Function MD5Encrypt(ByVal EncString As String) As String
  2.         'Variable Declarations
  3.         Dim MD5String As String
  4.         Dim EncStringBytes() As Byte
  5.         Dim Encoder As New UTF8Encoding
  6.         Dim MD5Hasher As New MD5CryptoServiceProvider
  7.  
  8.         'Converts the String to bytes
  9.         EncStringBytes = Encoder.GetBytes(EncString)
  10.  
  11.         'Generates the MD5 Byte Array
  12.         EncStringBytes = MD5Hasher.ComputeHash(EncStringBytes)
  13.  
  14.         'Create MD5 hash
  15.         MD5String = BitConverter.ToString(EncStringBytes)
  16.         MD5String = MD5String.Replace("-", "")
  17.  
  18.         'Returns the MD5 encrypted string to the calling object
  19.         Return MD5String
  20.  
  21.     End Function


This Hack is part of the ASP.NET Hacks collection

452 Rating: 4.3/5 (6 votes cast)