ASP.NET md5 function
I was pleasantly surprised to found that using System.Security.Cryptography you can create a function that calculates the MD5 hash of string.
Here’s an C# example:
using System.Security.Cryptography;
using System.Text;
public string md5(string aString)
{
byte[] byteStr = Encoding.UTF8.GetBytes(aString);
MD5 md5Provider = new MD5CryptoServiceProvider();
return Encoding.UTF8.GetString(md5Provider.ComputeHash(byteStr));
}
Here’s the same function in VB.NET:
Imports System.Security.Cryptography
Imports System.Text
Public Function md5(ByVal aString As String) As String
Dim byteStr() As Byte = Encoding.UTF8.GetBytes(aString)
Dim md5Provider As MD5 = New MD5CryptoServiceProvider()
Return Encoding.UTF8.GetString(md5Provider.ComputeHash(byteStr))
End Function

One Comments to “ASP.NET md5 function”
Yeah they have all kinds of amazing functions. You can even make strings into UPPERCASE! Absolutely amazing, I have no idea how they do it.