ASP.NET: Encrypt a string using MD5
From Wiki
Summary: Encrypt a string using MD5 encryption
Pass a string to the function and look at the returned string which is MD5 encrypted.
- Public Function MD5Encrypt(ByVal EncString As String) As String
- 'Variable Declarations
- Dim MD5String As String
- Dim EncStringBytes() As Byte
- Dim Encoder As New UTF8Encoding
- Dim MD5Hasher As New MD5CryptoServiceProvider
- 'Converts the String to bytes
- EncStringBytes = Encoder.GetBytes(EncString)
- 'Generates the MD5 Byte Array
- EncStringBytes = MD5Hasher.ComputeHash(EncStringBytes)
- 'Create MD5 hash
- MD5String = BitConverter.ToString(EncStringBytes)
- MD5String = MD5String.Replace("-", "")
- 'Returns the MD5 encrypted string to the calling object
- Return MD5String
- End Function
This Hack is part of the ASP.NET Hacks collection


