Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Community Wiki

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Navigation

Google Ads

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: 3.9/5 (15 votes cast)